简体   繁体   中英

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

I have this dataframe which I am plotting using df.plot and 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

Which I am plotting using

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

I want to have a line of value 0.05 plotted on every subplot. The only problem is I'm not sure how to create it since the x axis is non-numeric (ie. Jan, Feb etc).

I try using axhline as recommended in comments

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

And I get 'numpy.ndarray' object has no attribute 'axhline'

Thank you in advance for help!

Just use 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)

阴谋

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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