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

Alternative fix to suppress scientific notation #169

Closed
Jacks349 opened this issue Jun 12, 2020 · 3 comments
Closed

Alternative fix to suppress scientific notation #169

Jacks349 opened this issue Jun 12, 2020 · 3 comments
Labels
question Further information is requested

Comments

@Jacks349
Copy link

Jacks349 commented Jun 12, 2020

Yesterday i asked if there was a way to avoid scientific notation when charting (#165), so i thought i would share my solution.

There are three ways to go:

  1. Scale your dataframe data to a magnitude that doesn't require scientific notation, there is a good example made by @DanielGoldfarb on how to do this on the issue i linked.

  2. Use the followig solution

  3. A similar solution to option 2) that doesn't require using your own formatter:
    Here is how i did it:

fig, axlist = mpf.plot(df, returnfig=True) # MAKE SURE TO SET returnfig=True. IF YOU ARE SAVING THE CHART USING savefig, REMOVE IT, THE CHART WILL BE SAVED LATER

ax1 = axlist[0]
ax1.yaxis.set_major_formatter(FormatStrFormatter('%.8f'))

#If you want to save the chart
fig.savefig('mychart.png') #Saving the chart

Here is how i did it.
The problem with this solution:
It works well with the candlestick chart, but for some reason the Volume subplot will still use scientific notation. I don't know if that's an error with my code or if it's because they are two different charts, but in case anyone knew how to fix that aswell or add to this, it's welcome.

  • The prices are rendered without scientific notation, which is what we wanted!
  • The volume is still rendered with scientific notation

I created this issue to share my own solution as well as to try to improve it and make it work with the volume chart. I think it can be useful to anyone who would like to do the same with a fairly simple fix.

@Jacks349 Jacks349 added the question Further information is requested label Jun 12, 2020
@DanielGoldfarb
Copy link
Collaborator

The volume subplot will be in axlist[1] or axlist[2] (i forget which, would have to check the code). Or you could just try looping for ax in axlist: and reformat them all.

@Jacks349
Copy link
Author

Jacks349 commented Jun 12, 2020

Yes indeed, formatting them using a loop worked!
Here is how i did it:

for ax in axlist:
    ax.yaxis.set_major_formatter(FormatStrFormatter('%.8f'))

So, you can avoid scientific notation on a single subplot by selecting its index from the axlist list, or it can be avoided on all the subplots at once by using a loop, like i did.

Thanks @DanielGoldfarb ! I hope this will be useful for other devs too!

@char101
Copy link

char101 commented Jun 12, 2020

If I remember it correctly,

  • axlist[0] = right y, the axis show when there is only one chart
  • axlist[1] = left y, the axis for overlay (subplots)
  • axlist[2] = right y on the volume
  • axlist[3] = left y on the volume (for volume overay/indicator)

By the way, volume should always be integer, why do you want to format it as %.8f. It is better to adjust the formatting with the data scale.

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

3 participants