3

I have a dataframe df with 2 columns I want to plot together and days as index:

           | col1  | col2   | col3 | ...
2020-01-01 | 1     | 300000 | ...
2020-01-02 | 1000  | 600000 | ...
2020-01-03 | 3000  | 50000  | ...

Plotting col1 + col2 via

df[["col1", "col2"]].plot()

shows values from 0 till 1.0 and at the top "1e6" like in this example: https://i.sstatic.net/tJjgX.png

I want the full value range on the y-axis and no scientific notation. How can I do this via pandas .plot() or matplotlib?

3 Answers 3

6

You have several options:

Option One: With Matplotlib

axes=fig.add_axes([0,0,1,1])
axes.set_xticks() # with list or range() inside
axes.set_yticks() # with list or range() inside

#You can also label the ticks with your desired values
axes.set_xticklabels() # with list or range() inside
axes.set_yticklabels() # with list or range() inside

Option Two: Change Pandas settings

pd.set_option('display.float_format', lambda x: '%.3f' % x)

or

pd.options.display.float_format = '{:.2f}'.format

I believe option one is better since you need it only for the graph and don't necessarily want to modify your dataframe columns.

Cheers!

Sign up to request clarification or add additional context in comments.

Comments

4

You can try changing the axes.formatter.limits property of rcParams:

plt.rcParams["axes.formatter.limits"] = (-5, 12)

Matplotlib uses scientific notation if log10 of the axis range is smaller than the first or larger than the second.

You can customize the lower and upper limits for desired output.

Comments

-3

Use .set_ylim([min,max]) for setting the y axis limit of the plot

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.