Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable the minor ticks of log-plot in Matplotlib?

Here is a simple plot:

enter image description here

1) How to disable the ticks? 2) How to reduce their number?

Here is a sample code:

from pylab import * import numpy as np  x = [5e-05, 5e-06, 5e-07, 5e-08, 5e-09, 5e-10] y = [-13, 14, 100, 120, 105, 93]  def myfunc(x,p):     sl,yt,yb,ec=p         y = yb + (yt-yb)/(1+np.power(10, sl*(np.log10(x)-np.log10(ec))))     return y  xp = np.power(10, np.linspace(np.log10(min(x)/10), np.log10(max(x)*10), 100))  pxp=myfunc(xp, [1,100,0,1e-6]) subplot(111,axisbg="#dfdfdf") plt.plot(x, y, '.', xp, pxp, 'g-', linewidth=1)    plt.xscale('log')  plt.grid(True,ls="-", linewidth=0.4, color="#ffffff", alpha=0.5)   plt.draw() plt.show() 

Which produces: enter image description here

like image 304
Danial Tz Avatar asked May 28 '12 07:05

Danial Tz


People also ask

How do I turn off minor ticks in MatPlotLib?

Matplotlib removes both labels and ticks by using xticks([]) and yticks([]) By using the method xticks() and yticks() you can disable the ticks and tick labels from both the x-axis and y-axis.

How do I get rid of Ylabel in MatPlotLib?

To hide or remove X-axis labels, use set(xlabel=None). To display the figure, use show() method.

How do I use minor ticks in MatPlotLib?

Minor ticks can be turned on without labels by setting the minor locator. Minor tick labels can be turned on by setting the minor formatter. MultipleLocator places ticks on multiples of some base. FormatStrFormatter uses a format string (e.g., '%d' or '%1.2f' or '%1.1f cm' ) to format the tick labels.


1 Answers

plt.minorticks_off() 

Turns em off!

To change the number of them/position them, you can use the subsx parameter. like this:

plt.xscale('log', subsx=[2, 3, 4, 5, 6, 7, 8, 9]) 

From the docs:

subsx/subsy: Where to place the subticks between each major tick. Should be a sequence of integers. For example, in a log10 scale: [2, 3, 4, 5, 6, 7, 8, 9]

will place 8 logarithmically spaced minor ticks between each major tick.

like image 134
fraxel Avatar answered Sep 25 '22 08:09

fraxel