-
Notifications
You must be signed in to change notification settings - Fork 624
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
Plotting options for y-axis grid increment, volume y-axis labels on the left #295
Comments
Hi Tyler, Volume y-axis values displayed on the left Presently, with mplfinance, the only way I can think to put volume and price on opposite sides is if you put an addplot() on the same panel as the volume and specify, in the As an example:
s = mpf.make_mpf_style(base_mpf_style='default',y_on_right=True)
apds = mpf.make_addplot((df['PercentB']*100),panel=1,color='g',y_on_right=False,secondary_y=True,ylabel='% B')
mpf.plot(df,type='candle',addplot=apds,volume=True,style=s) This should give you a plot that looks like this: Let me know if that is what you were looking to do, or if maybe I misunderstood your question. All the best. --Daniel (I will answer your question about Y-axis grid increment separately in a little while.) |
Regarding
Correct me if I am wrong, but it sounds to me that what you are looking to do is not so much change the grid increments (which is controled by the location of the major ticks) but rather you want to change the upper and lower limits of the y-axis. This can be done using the kwarg Regarding
From this, it sounds to me like you are "monitoring" or animating your plot based on new incoming data, and you want to adjust the y-axis limits based on the newest data. If this is correct, then as a demostration of doing this, I would suggest the following: Take one of my animation demos, for example recent = 22
if len(data) > recent:
ymin = min(data['Low'][-recent:])
ymax = max(data['High'][-recent:])
xtra = (ymax - ymin) *0.02
ymin -= xtra
ymax += xtra
mpf.plot(data,type='candle',addplot=apds,ax=ax_main,volume=ax_volu,ylim=(ymin,ymax)) Then run Let me know if that helps. All the best. --Daniel P.S. one last point, just in case you are not aware: typically, when running matplotlib outside of a notebook or lab, you can access the zoom tool in the user interface that allows you to zoom in on a specific portion of the plot. The zoom tool can also be accessed within a notebook if you install the matplotlib jupyter extension. |
Hi @DanielGoldfarb, thanks! Both of your tips and examples help. I'm streaming frames generated with savefig, so I don't have the zoom capability of the stream figured out in my browser yet. Thanks though, I hadn't thought about exploring zoom options. |
I made it a little more complex; something like this seems right for me. For live-streaming/animation I think standardizing the visual magnitude of the price movements and candlestick sizes (by having a constant y-axis and x-axis range) helps keep a particular stock's activity in context. Reducing changes in the y-axis limits and grid positions as much as possible helps you characterize the pattern and trends since there's less shifting around. Since it's live streaming there's a lot of variability in the current tick's values (and potentially the y-axis and grid positions) on a second-by-second basis. Just as important in my use case, there's also variability in the volatility which is hard to visualize if the y-axis doesn't have a fixed height- so being able to visualize the volatility by standardizing the y-axis range is helpful. This was a really specific use case, so again I appreciate you taking your time to help!
|
Tyler, |
If you have them handy, could you point me in the direction of the documentation or lines of mplfinance code where these can be customized please?
I checked the mplfinance and mpl docs on plotting options:
https://github.com/matplotlib/mplfinance/blob/master/examples/styles.ipynb
https://matplotlib.org/tutorials/introductory/customizing.html
But I didn't see configuration options for these 2:
Y-axis grid increment- customizing the price difference between the lines in the grids. Abnormally tall single candlesticks can ruin the proportion of the rest of the candlesticks and price movements. E.g. After the tall single candlestick it looks like there's no or very little price movement (I'm plotting 1 minute and 10s charts). It's hard to judge the price movements and candlestick shapes and patterns since the plot is too zoomed out.
An example use case would be fixing the y-axis height to display .60 cents between bottom and top. That way the proportion would be the same regardless of intraday volatility. When a new value exceeds the bottom or top, the bottom or top y-limit of the plot could be moved there. When older values are outside of the .60 cent range from the newest value they would be out of bounds on the plot and not displayed. Since that's pretty specific, just some tips on where the best place to start would be should help.
Volume y-axis values displayed on the left. I'd like to display the TA addplot y-axis value on the right (and keep the price y-axis values on the right). I think the newest TA values (where the numeric values themselves might have significance) displayed on the right by the newest candlestick makes more sense for me than having the volume values on the right (since volume can be roughly estimated or compared by bar size).
Thanks,
Tyler
The text was updated successfully, but these errors were encountered: