Matplotlib Scaling Y Axis in Pareto Chart

72 views Asked by At

I'm trying to show some data in a Pareto chart. My current chart looks like this:

pareto chart

I would like to scale my left y axis growing exponentially as 10^0, 10^1, 10^2, etc. I would also like it to display the numbers "1", "10", "100", etc instead of in 10^x style. I know I can set a ylim, but I don't want it to grow linearly. Any help would be much appreciate. Here is my current code for the plot:

fig, axes = plt.subplots()
ax1 = df1.plot(use_index=False,x='index_column', y='total_dollars_spent',  kind='bar', ax=axes)
ax2 = df1.plot(use_index=True, y='percent', marker='D', color="C1", kind='line', ax=axes, secondary_y=True)
ax1.set_ylim([0,15000])
ax2.set_ylim([0,110])
plt.show()
1

There are 1 answers

0
Raj K On
  1. Call ax1.yscale('log') and ax2.yscale('log') to set the Y-axes to log scales
  2. You'll need to call set_yticks() on ax1 and ax2 with manually-calculated Y-ticks, it seems: https://stackoverflow.com/a/61022254/6279356.