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 can i show numbers not in exponential form on my x axis? #165

Closed
Jacks349 opened this issue Jun 10, 2020 · 4 comments
Closed

How can i show numbers not in exponential form on my x axis? #165

Jacks349 opened this issue Jun 10, 2020 · 4 comments
Labels
question Further information is requested

Comments

@Jacks349
Copy link

I'm using a dataframe to chart some OHLC data, here is a sample:

                   Date        Open        High         Low       Close           Volume
0   2020-05-21 02:00:00  0.00003956  0.00003960  0.00003924  0.00003946   21102.00000000
1   2020-05-21 02:30:00  0.00003933  0.00003951  0.00003933  0.00003951    1924.00000000
2   2020-05-21 03:00:00  0.00003934  0.00003946  0.00003930  0.00003934   14208.00000000
3   2020-05-21 03:30:00  0.00003944  0.00003951  0.00003936  0.00003951    2462.00000000
4   2020-05-21 04:00:00  0.00003951  0.00003951  0.00003932  0.00003932     262.00000000

Since the prices are very low numbers they will be charted using the exponential form, is there any way to prevent that?

q

PS: i just saw the new added features, and i'm amazed at how awesome this library keeps getting :)

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

I want to add this feature at some point, but until we have it, for now you have two choices that I know of:

  1. You can obviously scale all your data to a magnitude for which matplotlib will not default to scientific notation.
  2. There following comments contain a suggestion that involves using the figure and axes returned by mpf.plot(...,returnfig=True)
    a. Implement y-scale (ex: log) #21 (comment)
    b. logarithmic scale #138 (comment)

@Jacks349
Copy link
Author

Thank you for the quick answer! Option 2 seems to do the trick; do you know how can i scale the data as you mentioned in option 1?

@DanielGoldfarb
Copy link
Collaborator

@Jacks349 ,

Once you have the data in a DataFrame, you can simply multiple the dataframe by a constant:

print(df)
                         Open      High       Low     Close   Volume
Date                                                                
2020-05-21 02:00:00  0.000040  0.000040  0.000039  0.000039  21102.0
2020-05-21 02:30:00  0.000039  0.000040  0.000039  0.000040   1924.0
2020-05-21 03:00:00  0.000039  0.000039  0.000039  0.000039  14208.0
2020-05-21 03:30:00  0.000039  0.000040  0.000039  0.000040   2462.0
2020-05-21 04:00:00  0.000040  0.000040  0.000039  0.000039    262.0

Now multiply the DataFrame by 1000000:

df *= 1000000
print(df)
                      Open   High    Low  Close        Volume
Date                                                         
2020-05-21 02:00:00  3.956  3.960  3.924  3.946  2.110200e+09
2020-05-21 02:30:00  3.933  3.951  3.933  3.951  1.924000e+08
2020-05-21 03:00:00  3.934  3.946  3.930  3.934  1.420800e+09
2020-05-21 03:30:00  3.944  3.951  3.936  3.951  2.462000e+08
2020-05-21 04:00:00  3.951  3.951  3.932  3.932  2.620000e+07

Notice however that the Volume got scaled also.
To avoid scaling the Volume you can do:

df.loc[:,['Open','High','Low','Close']] *= 100000

Now, only the OHLC were scaled:

                      Open   High    Low  Close   Volume
Date                                                    
2020-05-21 02:00:00  3.956  3.960  3.924  3.946  21102.0
2020-05-21 02:30:00  3.933  3.951  3.933  3.951   1924.0
2020-05-21 03:00:00  3.934  3.946  3.930  3.934  14208.0
2020-05-21 03:30:00  3.944  3.951  3.936  3.951   2462.0
2020-05-21 04:00:00  3.951  3.951  3.932  3.932    262.0

Original mpf.plot(df,type='candle',volume=True)
image


OHLC scaled mpf.plot(df,type='candle',volume=True)
image

@Jacks349
Copy link
Author

Jacks349 commented Jun 11, 2020

Awesome, thank you Daniel! I think for now i'll go with the second option, it does the trick! Thank you again!

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