zoukankan      html  css  js  c++  java
  • 折线图-小案例

    01-设置全局字体+大小
    02-绘制多条直线
    03-折线图-蓝色点+红色线+坐标


    01-设置全局字体+大小

    import matplotlib.pyplot as plt
    import matplotlib  # 载入matplotlib完整库
    
    matplotlib.rcParams['font.family'] = 'Microsoft Yahei'  # 字体,改为微软雅黑,默认 sans-serif
    matplotlib.rcParams['font.size'] = 32  # 字体大小,整数字号,默认10
    
    a = range(10)
    x = a
    y = a
    plt.plot(x, y)  # 折线图
    plt.grid()  # 设置网格
    plt.show()  # 显示图形
    

      


    02-绘制多条直线

    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib  # 载入matplotlib完整库
    
    matplotlib.rcParams['font.family'] = 'Microsoft Yahei'  # 字体,改为微软雅黑,默认 sans-serif
    matplotlib.rcParams['font.size'] = 32  # 字体大小,整数字号,默认10
    
    a = np.arange(10)
    plt.figure(figsize=(20, 20), dpi=80)
    # 方法一:
    # plt.plot(a, a, a, a * 1.5, a, a * 3)  # 折线图
    # 方法二:
    plt.plot(a, a)  # 折线图
    plt.plot(a, a * 1.5)  # 折线图
    plt.plot(a, a * 3)  # 折线图
    
    plt.grid()  # 设置网格
    plt.show()  # 显示图形
    

      


    03-折线图-蓝色点+红色线+坐标

    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib  # 载入matplotlib完整库
    
    matplotlib.rcParams['font.family'] = 'Microsoft Yahei'  # 字体,改为微软雅黑,默认 sans-serif
    # matplotlib.rcParams['font.size'] = 32  # 字体大小,整数字号,默认10
    
    a = np.arange(10)
    # y = x ** 2
    x = a
    y = list(map(lambda i: i ** 2, a))
    
    plt.figure(figsize=(20, 20), dpi=80)
    
    plt.plot(x, y, color='r', markerfacecolor='blue', marker='o')
    for i, j in zip(x, y):
        plt.text(i + 0.3, j - 6, (i, j), ha='center', va='bottom', fontsize=30)  # 标记文本
    
    plt.legend(apha=0.1)
    
    plt.grid()  # 设置网格
    plt.show()  # 显示图形
    

      

  • 相关阅读:
    Linux操作系统定时任务系统 Cron 入门
    ssh命令远程登录
    jQuery 中 attr() 和 prop() 方法的区别
    javascript深入理解js闭包
    怎样使用Markdown
    顺颂商祺
    利用Code128字体将文本转换为code128条形码
    如何看懂Code128条形码
    SSH原理及操作
    ssh 22端口号拒绝
  • 原文地址:https://www.cnblogs.com/andy9468/p/9891204.html
Copyright © 2011-2022 走看看