Skip to content

Setting limits for Y-axis #106

New issue

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

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

Already on GitHub? # to your account

Closed
Nextein opened this issue Apr 24, 2020 · 8 comments
Closed

Setting limits for Y-axis #106

Nextein opened this issue Apr 24, 2020 · 8 comments
Labels
enhancement New feature or request question Further information is requested released code merged into repo AND released to Pypi

Comments

@Nextein
Copy link

Nextein commented Apr 24, 2020

Hello,
I'm trying to plot MACD using mplfinance but the histogram is an issue. It was mentioned elsewhere that histograms in the lower panel are not implemented yet and a trick around it is to set the 'Volume' column to the histogram values we want to plot and set volume=True in mpf.plot(). The issue with his is that the MACD lines don't fit in the lower panel with the scale used for the volume. As a result, it would be necessary to have the MACD lines in a separate y-axis than the 'Volume' histogram.

Using make_addplots() to add lines to the lower panel, how do you make them have a different y-axis than the volume?

Thank you for your time,

Marc

@Nextein Nextein added the question Further information is requested label Apr 24, 2020
@DanielGoldfarb
Copy link
Collaborator

Hmmm. Yeah, good point about the limitations on the workaround. There is code in there that specifically clips the lower part of the volume (because for very large volumes it's hard to see their differences if we let the y-axis go to zero).

Let me see what i can come up with as a quick fix, hopefully for next week. Ultimately will add another panel (subplot) and bars, but currently finishing up some other enhancements.

@Nextein
Copy link
Author

Nextein commented Apr 24, 2020

Furthermore, a MACD histogram has negative values which when plotted using the volume trick aren't visible since the plot places the zero close to the bottom of the axis assuming all the volume values are gonna be above it (positive). This would again need an option to set the limits for the y-axis but for the volume y-axis in the lower panel.

DanielGoldfarb added a commit to DanielGoldfarb/mplfinance that referenced this issue Apr 24, 2020
DanielGoldfarb added a commit that referenced this issue Apr 24, 2020
implement set_ylim quick fix (issues #77 and #106)
@DanielGoldfarb
Copy link
Collaborator

I have just added a quick-fix for this issue. It is not on Pypi (and will not be for another week or so) but you can grab the change by cloning this repository and installing it locally.

There are now two additional kwargs to mpf.plotting(). They are set_ylim (for the main panel) and set_ylim_panelB (for the lower panel). Both kwargs expect a list or tuple of length two, where the entries are int or float, in the order ymin, ymax. Thus for example:

mpf.plot(df,...,volume=True,...,set_ylim_panelB=(-100,100))

This will, for the time being, allow you to override whatever mplfinance decides to do for the y-axis limits, while we come up with a better more permanent solution. Let me know if you have any questions. All the best. --Daniel

@DanielGoldfarb DanielGoldfarb added merged / awaiting release to pypi code merged into repo, but not yet released to Pypi enhancement New feature or request labels Apr 30, 2020
@DanielGoldfarb DanielGoldfarb added released code merged into repo AND released to Pypi and removed merged / awaiting release to pypi code merged into repo, but not yet released to Pypi labels May 6, 2020
@myang80
Copy link

myang80 commented Oct 18, 2020

Hello,

Thanks for the good work. But it seems "set_ylim" has been replace by "ylim". What is the new command for "set_ylim_panelB" now? I tried "ylim_panelB", but it did not work ... Thank you!

@DanielGoldfarb
Copy link
Collaborator

@myang80
You can use ylim in either (or both) mpf.plot() and mpf.make_addplot(). The ylim will be applied to whatever panel is set for that particular plot() or make_addplot() call (using the panel keyword, or allowing panel to default).

Please see https://github.com/matplotlib/mplfinance/blob/master/examples/panels.ipynb for more information on the way that panels are handled now, since the concept of "main panel" and "lower panel" or "panelB" have been deprecated (in favor of a simple panel number).

@DanielGoldfarb
Copy link
Collaborator

DanielGoldfarb commented Oct 19, 2020

As I am thinking about this now, it seems to me, if you want to set your own ylim specifically for the volume data, and there is no make_addplot() data on the volume panel, then you may have to add a make_addplot() to that panel in order to modify the ylim for volume.

Please let me know if this is an issue for you. It may make sense to add a volume_ylim kwarg (since there is a volume_panel kwarg), or come up with some other solution other than forcing the user to do make_addplot() only for the purpose of setting ylim on the volume. Please let me know.

Thank you. --Daniel

@myang80
Copy link

myang80 commented Oct 19, 2020

Hi Daniel,

Thanks for your help! mplfinance is a really useful tool and I appreciate your excellent support on it!

The issue I have is that I am trying to plot accumulative volume during the up (positive) and down (negative) period along with the OHLC chart. So, it is not a volume actually. When the "volume" is negative, it seems the volume range is too small to cover the whole data. Please find the screenshot below.
image

I am new to python and mplfinance, and I will look into how to use make_addplot().

Thank you very much!

Meng

@DanielGoldfarb
Copy link
Collaborator

Meng,
Thanks for providing more details on what you are trying to accomplish. Please let me know how it works out with make_addplot().
--Daniel

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request question Further information is requested released code merged into repo AND released to Pypi
Projects
None yet
Development

No branches or pull requests

3 participants