繁体   English   中英

将水平线添加到具有非数字 x 轴的多个子图

[英]Add a horizontal line to multiple subplots with non-numeric x axis

我有这个数据框,我正在使用 df.plot 和 subplots 进行绘制。

            AMLR   SAag    MDB   SMDB   SWWA
All_months  0.000  0.000  0.000  0.041  0.000
Jan         0.799  0.560  0.664  0.612  0.026
Feb         0.591  0.230  0.139  0.211  0.017
Mar         0.980  0.411  0.034  0.082  0.546
Apr         0.243  0.420  0.692  0.890  0.795
May         0.302  0.880  0.706  0.850  0.334
June        0.952  0.480  0.848  0.261  0.235
July        0.369  0.480  0.055  0.970  0.658
Aug         0.953  0.530  0.184  0.241  0.523
Sep         0.761  0.450  0.650  0.271  0.723
Oct         0.151  0.047  0.000  0.004  0.690
Nov         0.672  0.500  0.001  0.043  0.834
Dec         0.557  0.170  0.012  0.039  0.007

我正在使用

correlationdataplot = correlationdf.plot(subplots = True, style ='.', figsize = (10,10))

我想在每个子图上绘制一条值为 0.05 的线。 唯一的问题是我不确定如何创建它,因为 x 轴是非数字的(即 Jan、Feb 等)。

我尝试按照评论中的建议使用 axhline

correlationdataplot = correlationmonthsonlydf.plot(subplots = True, style ='.', figsize = (10,10))
correlationdataplot.axhline(y=0.05, xmin=0, xmax=1, colour = 'r', linestyle = '--')

我得到 'numpy.ndarray' 对象没有属性 'axhline'

预先感谢您的帮助!

只需使用axhline

figure = correlationdf.plot(subplots = True, style ='.', figsize = (10,10))
for ax in figure:
    ax.axhline(y=0.05, linestyle = '--')
    ax.set_xticks(range(len(correlationdf)))
    ax.set_xticklabels(correlationdf.index)

阴谋

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM