简体   繁体   中英

Custom hlines in mplfinance python

I am plotting four horizontal lines using the statement below. For one of the lines I would like to use a different format (color and line style) than the other three lines.

mpf.plot(df2,hlines=[aa,h,l,x82],type='candle',style='yahoo',volume=False,figsize=(9, 5),title=str(c[15]),addplot=b)

Would appreciate any assistance!

As explained in the "using lines" tutorial it is possible to pass a dict in for the hlines kwarg. This allows you to specify the following attributes of the lines: colors , linestyle , linewdiths and alpha . So, for example, given your code above:

mpf.plot(df2,
         hlines=[aa,h,l,x82],
         type='candle',
         style='yahoo',
         volume=False,
         figsize=(9, 5),
         title=str(c[15]),
         addplot=b)

If you wanted all four hlines to be different you could do the following:

mpf.plot(df2,
         hlines=dict(hlines=[aa,h,l,x82],
                     colors=['r','g','b','c'],
                     linestyle=['-','--','-.',':'],
                     linewidths=[2,4,6,8]),
         type='candle',
         style='yahoo',
         volume=False,
         figsize=(9, 5),
         title=str(c[15]),
         addplot=b)

If you wanted online one line to be different you could do something like this:

mpf.plot(df2,
         hlines=dict(hlines=[aa,h,l,x82],
                     colors=['g','g','g','c'],
                     linestyle=['-','-','-',':'],
                     linewidths=[2,2,2,6]),
         type='candle',
         style='yahoo',
         volume=False,
         figsize=(9, 5),
         title=str(c[15]),
         addplot=b)

And, of course, if you wanted all four lines to be the same, you could do this:

mpf.plot(df2,
         hlines=dict(hlines=[aa,h,l,x82],
                     colors='c',
                     linestyle='-',
                     linewidths=4),
         type='candle',
         style='yahoo',
         volume=False,
         figsize=(9, 5),
         title=str(c[15]),
         addplot=b)

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