Skip to content
Advertisement

I get a double decade when plot semi-log x-axis : how to force display each decade?

I am faced with a simple problem. When I do a semi-log plot(log on x-axis) like this :

JavaScript

Then, I get the following figure :

semi-log plot

As you can see, I have double decades on x-axis: how to force matplotlib to draw each decade and not passing for example from 10^1 directly to 10^3?

And finally, how to make appear the minor xtiks for each decade plotted ?

Edit

The solution given doesn’t recognize the parameter nbins :

I get the following error:

plt.locator_params(axis="x", nbins=20) File "/opt/intel/intelpython3/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2691, in locator_params return gca().locator_params(axis=axis, tight=tight, **kwargs) File "/opt/intel/intelpython3/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 2913, in locator_params self.xaxis.get_major_locator().set_params(**kwargs) TypeError: set_params() got an unexpected keyword argument 'nbins'

Advertisement

Answer

You could use nbins = number of ticks you want

JavaScript

This post might help with adding the minor ticks on log scale.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement