Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance hlines and alines #219

Open
fxhuhn opened this issue Jul 17, 2020 · 3 comments
Open

Enhance hlines and alines #219

fxhuhn opened this issue Jul 17, 2020 · 3 comments
Labels
question Further information is requested

Comments

@fxhuhn
Copy link
Contributor

fxhuhn commented Jul 17, 2020

Hi Daniel,

first of all great compliments in advance. I'm always excited about what you bring in every release with this library for extensions.

Step by step I add each new function to the charts. Latest improvments are RSI in the middle, hlines and alines.
Currently I build up the alines and hlines as follows:

        hlines = {}
        hlines['values'] = swings_1
        hlines['colors'] = ['lightgrey' for x in range(len(swings_1))]
        hlines['linewidths'] = [1 for x in range(len(swings_1))]

        hlines['values'] += swings_2
        hlines['colors'] += ['grey' for x in range(len(swings_2))]
        hlines['linewidths'] += [1 for x in range(len(swings_2))]

            alines = list(zip(zip(df_breakout.d4_start, df_breakout.d4_high), zip(df_breakout.d4_end, df_breakout.d4_high)))
            alines += list(zip(zip(df_breakout.d4_start, df_breakout.d4_low), zip(df_breakout.d4_end, df_breakout.d4_low)))

mpf.plot(df,
                 type='candle',
                 volume=True,
                 volume_panel = 2,
                 addplot=add_plots,
                 title=myfilename ,
                 ylabel='Kurs',
                 ylabel_lower='Volumen',
                 style=s,
                 figscale=3.0,
                 figratio=(18, 10),
                 datetime_format = '%d.%m.%y',
                 xrotation = 20,
                 hlines=
                    dict(hlines=hlines['values'], colors=hlines['colors'], linestyle='dashed', linewidths=hlines['linewidths']),
                 alines= alines,
                 savefig=save,
                 tight_layout=True,
                 closefig=True)

If i would like to use different colors and sizes, would it be possible to add a list of dicts in the future? Something like ...
hlines = [dict_support_lines, dict_resistence_lines]
... so that the other parameters (eg. linestyle) can also be changed more easily?

csco_us

@fxhuhn fxhuhn added the question Further information is requested label Jul 17, 2020
@DanielGoldfarb
Copy link
Collaborator

Hi Markus,

At a quick glance, seems a reasonable request. I'm very busy on a couple of other items right now. Will take a closer look and come back with more specific comments in a few days. Thank you for sharing the chart and the code. By the way, that's an excellent chart! I love seeing the really creative things people are doing with mplfinance. Keep it up.

All the best. --Daniel

@HardRock4Life
Copy link

@fxhuhn, @DanielGoldfarb, is it possible to add labels on hlines or alines, so the line's value on plot would've been shown?

@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Aug 10, 2020

@HardRock4Life
It is possible, however these features are not yet directly built into mplfinance.

Instead you need to gain access to the Axes objects from mplfinance, and then use matplotlib directly for features such as text annotation and legends which you can find in the matplotlib documentation (for example https://matplotlib.org/3.3.0/api/axes_api.html#text-and-annotations).

To gain access to mplfinance's Axes objects, there are two ways:

1. set returnfig=True when calling plot:
 
fig, axlist = mpf.plot(data,...,returnfig=True,...)
 
axlist will be a list of axes corresponding to the panels from top to bottom, two axes per panel where the first is the primary axes and the next is the secondary axes. For example, if you have 3 panels then returnfig=True will return 6 Axes objects. axlist[0] and axlist[1] will be the primary and secondary axes, respectively, for panel 0. axlist[2] and axlist[3] will be the primary and secondary axes, respectively, for panel 1, etc.

2. Create your own Figure and Axes objects and pass these into mplfinance. You can see examples of how to do this here.

HTH. LMK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants