Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to turn on minor ticks only on y axis matplotlib

How can I turn the minor ticks only on y axis on a linear vs linear plot?

When I use the function minor_ticks_on to turn minor ticks on, they appear on both x and y axis.

like image 924
emad Avatar asked Oct 03 '12 14:10

emad


People also ask

How do I turn on 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.

How do you show minor ticks?

To locate minor ticks, use set_minor_locator() method. To show the minor ticks, use grid(which='minor'). To display the figure, use show() method.

How do you restrict Y-axis in Python?

To plot the boxplot, use boxplot() function. To set the y-axis limit, we use axis() method and we set xmin and xmax to None and ymin and ymax to -0.75 and 1.5 respectively.

How do I restrict axis in Matplotlib?

Import matplotlib. To set x-axis scale to log, use xscale() function and pass log to it. To plot the graph, use plot() function. To set the limits of the x-axis, use xlim() function and pass max and min value to it. To set the limits of the y-axis, use ylim() function and pass top and bottom value to it.


2 Answers

Nevermind, I figured it out.

ax.tick_params(axis='x', which='minor', bottom=False) 
like image 157
emad Avatar answered Sep 27 '22 20:09

emad


Here's another way I found in the matplotlib documentation:

import numpy as np from matplotlib import pyplot as plt from matplotlib.ticker import MultipleLocator  a = np.arange(100) ml = MultipleLocator(5) plt.plot(a) plt.axes().yaxis.set_minor_locator(ml) plt.show() 

This will place minor ticks on only the y-axis, since minor ticks are off by default.

like image 39
John Vinyard Avatar answered Sep 27 '22 18:09

John Vinyard