mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

ylim step size

Open johnnjuki opened this issue 3 years ago • 4 comments

how can i change the ylim to have a step size of 2? image

johnnjuki avatar Jul 22 '21 13:07 johnnjuki

John,

ylim controls the limits of the y-axis values (minimum and maximum). I believe you want to change the y-axis tick positions (not ylim). In your plot the major ticks are placed every 5 from 1910 to 1950. Can you confirm if that is what you are looking to do, that is setting ticks positions (not y-limits)?

DanielGoldfarb avatar Jul 22 '21 16:07 DanielGoldfarb

Yes, setting tick positions is what I'm looking to do.

johnnjuki avatar Jul 22 '21 16:07 johnnjuki

Currently working on an enhancement to allow you to modify the y-axis tick positions in mpf.plot(). It may be some time until complete, however in the meantime, as a workaround you can manually modify the ticks as follows:

Add returnfig=True to your call to mpf.plot(), and then set the y-ticks on the Axes object returned:

ylimits=(1908,1950)
yticks = [  yt for yt in range( ylimits[0], ylimits[-1], 2) ]

fig, axlist = mpf.plot(nq2006_04, style=s, show_nontrading=True, xrotation=0, ylim=ylimits,returnfig=True)

axlist[0].set_yticks(yticks)
mpf.show()

DanielGoldfarb avatar Jul 30 '21 18:07 DanielGoldfarb

Currently working on an enhancement to allow you to modify the y-axis tick positions in mpf.plot(). It may be some time until complete, however in the meantime, as a workaround you can manually modify the ticks as follows:

Add returnfig=True to your call to mpf.plot(), and then set the y-ticks on the Axes object returned:

ylimits=(1908,1950)
yticks = [  yt for yt in range( ylimits[0], ylimits[-1], 2) ]

fig, axlist = mpf.plot(nq2006_04, style=s, show_nontrading=True, xrotation=0, ylim=ylimits,returnfig=True)

axlist[0].set_yticks(yticks)
mpf.show()

Hi Daniel,

Is this workaround still needed, or did you already implement "modify the y-axis tick positions in mpf.plot()" ?.

traderblakeq avatar Nov 30 '22 13:11 traderblakeq