zoukankan      html  css  js  c++  java
  • 第一节 matplotlib简单使用

    from matplotlib import pyplot as plt
    import matplotlib
    
    # 设置字体大小
    font = {'family':'MicroSoft YaHei',
            'weight':'bold',
            'size':8}
    matplotlib.rc("font",**font)
    
    x = range(0,10)
    y1 = range(10,20)
    y = range(30,40)
    
    # 设置图片大小,figsize图片大小,dpi图片像素
    fig = plt.figure(figsize=(20, 10), dpi=60)
    
    # 保存图片
    plt.savefig("./t1.png")
    
    # 绘图,绘制同一个x轴的两个图形,label参数指定图例的名字,color参数指定线条的颜色,linestyle参数指定线条风格,linewidth线条粗细,alpha线条透明度
    plt.plot(x, y, label='第一', color='red', linestyle="--", linewidth=5, alpha=0.5)
    plt.plot(x, y1, label='第二', color='gold')
    
    # 设置坐标轴轴刻度,第一个参数可以是一个列表,第二个参数是字符串,但是必须跟第一个参数的个数保持一致,rotation显示x刻度旋转的度数
    plt.xticks(x,labels=["第{}个数".format(i) for i in list(x)], rotation=90)
    plt.yticks(y)
    
    # 给图片添加单位信息,和标题信息
    plt.xlabel('时间')
    plt.ylabel('速度')
    plt.title('这是一个标题')
    
    # 显示网格,可以通过调整刻度的稀疏来调整网格的大小,alpha调整网格线的透明度,linestyle网格线风格
    plt.grid(alpha=0.4, linestyle='-.')
    
    # 添加图例,图例名字在绘图函数中添加,可以通过loc参数指定图例位置
    plt.legend(loc='upper left')
    
    # 展示图形
    plt.show()
  • 相关阅读:
    1.7 All components require plug-in?
    1.6 Why only in China?
    1.5 A better alternative thing: React Native
    1.4 The usage of plug-in
    1.3 History of Android Plug-in Programing
    SQL Server 查询请求
    matplotlib 绘图的核心原理
    数据加密 第六篇:透明文件加密
    数据加密 第五篇:非对称密钥
    SSIS 数据类型 第二篇:变量的数据类型
  • 原文地址:https://www.cnblogs.com/kogmaw/p/12556400.html
Copyright © 2011-2022 走看看