You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue occurs when formatting an axis (y-axis in this example) with 'log' scale and manually setting the limits. The process of setting the major and minor tick locations then does not work as expected/ as usual.
Code for reproduction
importmatplotlib.pyplotaspltfig, ax=plt.subplots()
# This section (1) fails to set the major ticks to locations [14, 18, 22, 26]ax.set_yscale('log')
ax.set_ylim(13.5,26.5)
ax.set_yticks([14, 18, 22, 26])
# Adding this line results in section (1) working as expectedax.set_yticks([], minor=True)
# Trying to also set the location of minor ticks leads to the same failure as in section (1)ax.set_yticks([16, 16.5, 20, 24], minor=True)
# Adding this line leads to the expected output againax.set_yticklabels([], minor=True)
plt.show()
Actual outcome
Despite calling set_yticks in section (1), the actual y-ticks remain at their default location. This first part of the issue can be resolved by setting the minor tick locations to an empty list.
When also trying to set the location of minor ticks, however, it seems that labels are automatically created for these minor ticks.
Expected outcome
Calling set_yticks() should set the location of both major and minor ticks independently without the need of changing both at the same time or having to set the minor ticklabels to an empty list.
Additional information
No response
Operating system
Debian GNU/Linux 11
Matplotlib Version
3.5.1
Matplotlib Backend
QtAgg
Python version
3.9.2
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered:
What is happening here is that when you are zoomed in to under one decade what you are actually seeing is the minor ticks which are labeled. (The major ticks actually still are [ 1., 10., 100., 1000.], just none of them happen to be inside of the view range)
If you only call ax.set_yticks(..., minor=True), I think you will find that it does what you expect. This is probably sufficient for a one off plot/non-interactive.
A bit more generally, this behavior is controlled by the minor_thresholds and labelOnlyBase parameters/attribute of the LogFormatter for the minor ticks.(ax.yaxis.get_minor_formatter())
To disable minor tick labeling and use the major ticks as you initially wanted, you can use ax.yaxis.set_minor_formatter(mpl.ticker.NullFormatter()).
If the minor ticks themselves are problematic, then you may wish to instead/in addition change the minor locatorax.yaxis.set_minor_locator(mpl.ticker.NullLocator()) which will get rid of the actual tick mark/minor grid line.
Thank you @ksunden, this makes a lot of sense! I was unaware of this behavior of the LogFormatter.
Closing this issue as this is actually how it should work and I did not properly look into the documentation.
Bug summary
The issue occurs when formatting an axis (y-axis in this example) with 'log' scale and manually setting the limits. The process of setting the major and minor tick locations then does not work as expected/ as usual.
Code for reproduction
Actual outcome
Despite calling set_yticks in section (1), the actual y-ticks remain at their default location. This first part of the issue can be resolved by setting the minor tick locations to an empty list.
When also trying to set the location of minor ticks, however, it seems that labels are automatically created for these minor ticks.
Expected outcome
Calling set_yticks() should set the location of both major and minor ticks independently without the need of changing both at the same time or having to set the minor ticklabels to an empty list.
Additional information
No response
Operating system
Debian GNU/Linux 11
Matplotlib Version
3.5.1
Matplotlib Backend
QtAgg
Python version
3.9.2
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: