【问题标题】:Pandas / Plot.plt Line Graph, X Values horizontalPandas / Plot.plt 折线图,水平 X 值
【发布时间】:2018-09-23 04:11:10
【问题描述】:

如何传递一个参数来显示所有的 x 值以便人们可以读取它?还有,我怎样才能显示多行数据,并带有图例?

plt. plot(a, b, linewidth=2.0 )

【问题讨论】:

    标签: pandas plot linegraph


    【解决方案1】:

    您可以只显示 n-th x-ticks 并扩大绘图以容纳更多标签。

    df = pd.DataFrame(data=np.random.rand(10), index=pd.Series(np.random.rand(10)).astype(str)+'_index')
                                   0
    0.007017115173211574_index  0.963285
    0.434969747965131_index     0.547248
    0.18021258326382017_index   0.719402
    0.7815848046772174_index    0.061448
    0.8856299613744312_index    0.771062
    0.16840431221766328_index   0.524256
    0.8662531211345982_index    0.528706
    0.6389453277004077_index    0.287410
    0.7444490769967744_index    0.513631
    0.8965709043061524_index    0.892011
    
    plt.subplots(figsize=(20,15)) # make plot bigger
    plt.plot(df.index, df[0]*2, linewidth=.9) # plot several lines
    plt.plot(df.index, df[0].rename('1'),linewidth=.9) # plot several lines
    plt.xticks(df.index[::2]) # tick every 2nd label on x axis.
    plt.legend() # show legend
    

    【讨论】:

    • 什么意思? @pes04
    • @hellpander 看看我放入你的代码中的图像,我希望 x 轴值显示为该图像的样子
    • 你想要一个条形图吗?
    • 不关心图表类型。只是 xtick 值(注意我的第一篇文章它们是水平的,我希望它们是垂直的,就像第二张图片一样)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多