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.
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.
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.
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.
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.
Nevermind, I figured it out.
ax.tick_params(axis='x', which='minor', bottom=False)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With