mplfinance icon indicating copy to clipboard operation
mplfinance copied to clipboard

How can I change the Xtick of the plot

Open abugeralt opened this issue 4 years ago • 4 comments

image

As the picture shows, How can i change the Xtick to show the date by day.

abugeralt avatar Jun 01 '20 09:06 abugeralt

This is not directly available right now, but is definitely on the list of things to do. In the meantime you may try returnfig=True and see if there is a way to get creative and manipulate the xticks through the figure and axes list that are returned.

DanielGoldfarb avatar Jun 01 '20 13:06 DanielGoldfarb

You'll need to customize the tick locator. For example:

from matplotlib.ticker import MultipleLocator

fig, axlist = mpl.plot(..., returnfig=True)
axlist[0].xaxis.set_minor_locator(MultipleLocator(1))

Note: this is untested code. I don't remember if it the bottom ticks is a major or minor ticks. You might need to change change minor to major. Also with small charts the text will surely overlap.

This is how it might look like

PTBA

char101 avatar Jun 13 '20 03:06 char101

@char101: Hi, I tried your set_minor_locator suggestion in Google Colab with Version is 0.12.7a17. It did not work for me :(

One request: If I may ask, can you share the code for the image you shared ? (It looks super cool to me). Wizardry kind of 😄

msampathkumar avatar Jun 26 '21 16:06 msampathkumar

@msampathkumar Sorry it has been too long and I don't have the code anymore. To do most of the customization, most of the time you only need two things: access to the axes variable and matplotlib documentation.

char101 avatar Jun 26 '21 17:06 char101