• Python


    Python - Datacamp - Introduction to Matplotlib

    Datacamp: https://www.datacamp.com/

    # 1.py 基本matplotlib.pyplot子模块入门
    
    # Import the matplotlib.pyplot submodule and name it plt
    import matplotlib.pyplot as plt
    
    # Create a Figure and an Axes with plt.subplots
    fig, ax = plt.subplots()  
    
    # Call the show function 
    plt.show()
    # 2.py 添加数据
    
    import matplotlib.pyplot as plt
    
    # 月份
    MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    # 降雨量
    rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32] 
    
    # 数据
    data = {}
    data['MONTH'] = MONTH
    data['rainfall'] = rainfall
    
    # 创建数据以及轴 
    fig, ax = plt.subplots()
    
    # ax: (x, y)
    ax.plot(data['MONTH'], data['rainfall'])
    
    # 显示
    plt.show()
    # 3.py 自定义显示
    
    import matplotlib.pyplot as plt
    
    # 月份
    MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    # 降雨量
    rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32] 
    
    # 数据
    data = {}
    data['MONTH'] = MONTH
    data['rainfall'] = rainfall
    
    # 创建数据以及轴 
    fig, ax = plt.subplots()
    
    # ax: (x, y)
    ax.plot(data['MONTH'], data['rainfall'], color='b', marker='*', linestyle='--')
    
    # 显示
    plt.show()
    # 4.py 自定义标签以及抬头
    
    import matplotlib.pyplot as plt
    
    # 月份
    MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    # 降雨量
    rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32] 
    
    # 数据
    data = {}
    data['MONTH'] = MONTH
    data['rainfall'] = rainfall
    
    # 创建数据以及轴 
    fig, ax = plt.subplots()
    
    # ax: (x, y)
    ax.plot(data['MONTH'], data['rainfall'], color='b', marker='*', linestyle='--')
    
    # 标签
    ax.set_xlabel('Months')
    ax.set_ylabel('Rainfall in CAN')
    
    # 标题
    ax.set_title('Weather in CAN')
    
    # 显示
    plt.show()
    # 5.py 多重图表
    
    import matplotlib.pyplot as plt
    
    # 月份
    MONTH_F = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
    MONTH_L = ['Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    # 降雨量
    rainfall_canton_F = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60] 
    rainfall_shanghai_F = [61.79, 59.40, 94.99, 83.19, 92.78, 173.57]
    rainfall_canton_L = [238.22, 233.75, 194.35, 68.65, 38.40, 29.32]
    rainfall_shanghai_L = [148.84, 193.88, 109.60, 62.44, 54.14, 37.71]
    
    # 创建数据以及轴 
    fig, ax = plt.subplots(2, 2)
    
    # ax: (x, y)
    ax[0,0].plot(MONTH_F, rainfall_canton_F, color='b', marker='*', linestyle='--')
    ax[0,1].plot(MONTH_F, rainfall_shanghai_F, color='r', marker='o', linestyle='--')
    ax[1,0].plot(MONTH_L, rainfall_canton_L, color='b', marker='*', linestyle='--')
    ax[1,1].plot(MONTH_L, rainfall_shanghai_L, color='r', marker='o', linestyle='--')
    
    # 标签
    ax[0,0].set_xlabel('Months')
    ax[0,0].set_ylabel('Rainfall in Canton')
    ax[0,1].set_xlabel('Months')
    ax[0,1].set_ylabel('Rainfall in Shanghai')
    
    # 标题
    ax[0,0].set_title('Weather in Canton')
    ax[0,1].set_title('Weather in Shanghai')
    # 显示
    plt.show()
    # 6.py small multiples with shared y axis
    
    import matplotlib.pyplot as plt
    
    # 月份
    MONTH = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    # 降雨量
    rainfall = [44.10, 71.08, 93.36, 184.63, 286.79, 318.60, 238.22, 233.75, 194.35, 68.65, 38.40, 29.32] 
    # 温度
    temperature = [10, 14, 20, 22, 19, 25, 30, 31, 32, 29, 15, 16]
    
    # 数据
    data = {}
    data['MONTH'] = MONTH
    data['rainfall'] = rainfall
    data['temperature'] = temperature
    
    # Create a figure and an array of axes: 2 rows, 1 column with shared y axis
    fig, axes = plt.subplots(2, 1, sharey=True)
    
    axes[0].plot(data['MONTH'], data['rainfall'], color='b')
    axes[0].plot(data['MONTH'], data['temperature'], color='b', linestyle='--')
    
    axes[1].plot(data['MONTH'], data['rainfall'], color='b')
    axes[1].plot(data['MONTH'], data['temperature'], color='b', linestyle='--')
    
    plt.show()
    Resistance is Futile!
  • 相关阅读:
    Nginx之keepalived高可用工具
    Linux安装Nginx
    Nginx解决服务器宕机问题
    前端知识小札
    SQL入门(3):定义约束/断言assertion/触发器trigger
    SQL入门(2): Oracle内置函数-字符/数值/日期/转换/NVL/分析函数与窗口函数/case_decode
    Excel VBA入门(8): 快捷键/内置常量/代码调试/错误处理/代码优化
    小学生都看得懂的C语言入门(6): 字符串
    小学生都看得懂的C语言入门(5): 指针
    小学生都看得懂的C语言入门(4): 数组与函数
  • 原文地址:https://www.cnblogs.com/noonjuan/p/10827541.html
Copyright © 2020-2023  润新知