Srivatsan
Srivatsan

Reputation: 9363

Removing specific xaxis tick labels in a log-plot, matplotlib

I have a log-log contour plot for which I needed to display the minor ticks. So I used

ax.xaxis.set_minor_formatter(fmt("%.1f"))
ax.yaxis.set_minor_formatter(fmt("%.1f"))

where fmt is from matplotlib.ticker import FormatStrFormatter as fmt

This works fine and gives me all the minor ticks. However as you can see from the attached image, the x-axis ticks, especially 7.0,8.0 and 9.0 are the ticks that overlap, and I want to specifically remove only them, but have the other minor ticks as they are.

Is this possible? I am not able to find a code that removes specific minor ticks.

enter image description here

Upvotes: 0

Views: 989

Answers (1)

Srivatsan
Srivatsan

Reputation: 9363

Immediately after posting the question, I found an easy solution.

It is to use ax.xaxis.set_minor_locator(plt.FixedLocator([2,3,4,5]))

The list inside the FixedLocator does the job.

Upvotes: 1

Related Questions