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

How to show all date scales? #247

Open
Tombon-Jedi opened this issue Aug 23, 2020 · 6 comments
Open

How to show all date scales? #247

Tombon-Jedi opened this issue Aug 23, 2020 · 6 comments
Labels
question Further information is requested

Comments

@Tombon-Jedi
Copy link

in matplotlib,i can do like this:
ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1))

@Tombon-Jedi Tombon-Jedi added the question Further information is requested label Aug 23, 2020
@DanielGoldfarb
Copy link
Collaborator

There is no direct support for that inside mpfinance, but you can get access to the Figure and Axes, which will then allow you to directly use matplotlib methods ( such as ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1)) ).

There are two ways to get access to the Figure and Axes as described here.

Once you have access to the Axes, it may, or may not, be as simple as calling ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1)), I don't know, you will have to experiment and see. But I can tell you what the issue is that you may encounter and have to deal with:

If show_nontrading=False, which is the default show_nontrading value if not specified, then the actual x-axis values are not dates, but are integer values, corresponding to the row number of your dataframe from which the data was taken. Those integer values get formated as dates by an internal formatting function which gets assigned here depending on the value of show_nontrading.

As I mentioned, I don't know how this will interact with setting the major locator; it may be just fine with no issues at all. Please let me know how it works out, or if you have any further questions.

All the best. --Daniel

@Tombon-Jedi
Copy link
Author

Tombon-Jedi commented Aug 24, 2020

There is no direct support for that inside mpfinance, but you can get access to the Figure and Axes, which will then allow you to directly use matplotlib methods ( such as ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1)) ).

There are two ways to get access to the Figure and Axes as described here.

Once you have access to the Axes, it may, or may not, be as simple as calling ax.xaxis.set_major_locator(matplotlib.ticker.MultipleLocator(1)), I don't know, you will have to experiment and see. But I can tell you what the issue is that you may encounter and have to deal with:

If show_nontrading=False, which is the default show_nontrading value if not specified, then the actual x-axis values are not dates, but are integer values, corresponding to the row number of your dataframe from which the data was taken. Those integer values get formated as dates by an internal formatting function which gets assigned here depending on the value of show_nontrading.

As I mentioned, I don't know how this will interact with setting the major locator; it may be just fine with no issues at all. Please let me know how it works out, or if you have any further questions.

All the best. --Daniel

I have solved this problem by temporarily modifying the plotting.py
like this picture:
image
and this effect is as follows:
image

I can change the interval by modifying the parameter value of the 'MultipleLocator'

@DanielGoldfarb
Copy link
Collaborator

Thank you for providing your solution. I will take a look and perhaps provide a kwarg to integrate it as an option to mpf.plot().

@Tombon-Jedi
Copy link
Author

@DanielGoldfarb I just modified that part of the code of 'plotting.py', because I passed in the two parameters 'savefig' and 'tight_layout'. if a kwarg to integrate it as an option, this will consider more modifications.

@Tombon-Jedi
Copy link
Author

My fiinal picture version:
image
Thanks for mplfinance package !

@DanielGoldfarb
Copy link
Collaborator

@2628202057
Tombon,
Thank you so much for sharing you work, and the image of your plot. I love seeing the creative things that people are doing with mplfinance. All the best.
--Daniel

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

2 participants