zoukankan      html  css  js  c++  java
  • python3绘图示例5(基于matplotlib:正弦图等)

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-

    import numpy as np
    import pylab as py
    import matplotlib as pl
    import matplotlib.pyplot as plt


    # 图1-余弦图 正弦图
    x=np.linspace(-np.pi,np.pi,256,endpoint=True)

    y=np.cos(x)
    y1=np.sin(x)

    pl.plot(x,y)
    pl.plot(x,y1)
    pl.show()

    # 图1-余弦图 正弦图 自定义x y轴
    x=np.linspace(-np.pi,np.pi,256,endpoint=True)

    y=np.cos(x)
    y1=np.sin(x)

    pl.plot(x,y)
    pl.plot(x,y1)

    # 设置标题
    pl.title('function $sin$ and $cos$')

    # 设置x轴 范围
    pl.xlim(-3.0,3.0)

    # 设置y轴 范围
    pl.ylim(-1.0,1.0)

    # 显示的x轴刻度
    pl.xticks([-np.pi,-np.pi/2,0,np.pi/2,np.pi],[r'$-pi$',r'$-pi/2$',r'$0$',r'$+pi/2$',r'$+pi$'])

    # 显示的y轴刻度
    pl.yticks([-1,0,+1],[r'$-1$',r'$0$',r'$+1$'])

    pl.show()

    # 3条线-自定义
    x1=np.random.normal(30,3,100)
    x2=np.random.normal(20,2,100)
    x3=np.random.normal(10,3,100)

    py.plot(x1,label='plot1')
    py.plot(x2,label='plot2')
    py.plot(x3,label='plot3')

    # 起始位置 宽度 高度 图例位置(左:3-6-2,中:8-10-9,右:4-7-1) 列数 图例扩展至整个坐标轴 坐标轴和图例距离
    py.legend(bbox_to_anchor=(0.,1.02,1.,.102),loc=3,ncol=3,mode='expand',borderaxespad=0.)

    # 注解和数据使用相同坐标 xycoords='data' 注解位置 xytext=(5,38) 箭头属性和风格
    py.annotate('import value',(55,22),xycoords='data',xytext=(5,38),arrowprops=dict(arrowstyle='->'))

    py.show()


    # 线和柱状图
    mu=100
    simag=15
    np.random.normal(mu,simag,10000)

    x=np.arange(0,10,1)
    y=np.log(x)

    xe=0.1*np.abs(np.random.randn(len(y)))
    plt.bar(x,y,yerr=xe,width=0.4,align='center',ecolor='r',color='cyan',label='experiment #1')

    plt.xlabel('# measurement')
    plt.xlabel('Measured values')
    plt.title('measurement')
    plt.legend(loc='upper left')

    plt.show()



  • 相关阅读:
    List(双向链表)
    Queue(队列)
    Queue(队列)
    Stack(栈)
    Stack(栈)
    Vector(容器)
    gitlab代码库
    Jenkins自动化部署平台
    Maven私服仓库
    VM架构设计文档初稿v0.01
  • 原文地址:https://www.cnblogs.com/NiceTime/p/10125229.html
Copyright © 2011-2022 走看看