zoukankan      html  css  js  c++  java
  • pandas 初识(六)-可视化

    Pandas 在一张图中绘制多条线

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    df = pd.DataFrame({
        'color': ['red','red','red','blue','blue','blue'], 
        'x': [0,1,2,3,4,5],'y': [0,1,2,9,16,25]
    })

    实现

    fig, ax = plt.subplots()
    
    for key, group in df.groupby(['color']):
        ax = group(ax=ax, kind='line', x='x', y='y', c=key, label=key)
    
    plt.legend()
    plt.show()

    也可以

    ax = None
    for key, group in df.groupby(['color']):
        ax = group(ax=ax, kind='line', x='x', y='y', c=key, label=key)
    
    plt.legend()
    plt.show()

     实现二,序列形式

    df_r = df[df["color"] == "red"]
    df_b = df[df["color"] == "blue"]
    plt.title('混合图')  #标题
    plt.plot(df_r.x, df_r.y, color='red', label='red')
    plt.plot(df_b.x, df_b.y, color='blue', label='blue')
    plt.legend()  #显示上面的label
    plt.xlabel('index')
    plt.ylabel('count')
    plt.show()
  • 相关阅读:
    软件测试常见概念
    Apollo简介及工作原理
    bug的编写技巧与级别划分
    native与H5优缺点及H5测试
    优惠券测试
    go语言-for循环
    go语言-流程控制--if
    go语言-二进制与位运算
    cookie和session
    AJAX
  • 原文地址:https://www.cnblogs.com/spaceapp/p/11771945.html
Copyright © 2011-2022 走看看