Why do the minor tick marks never appear even in matplotlib if I turn them on and set the minor locator?

Viewed 21

Here is the code

import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
sns.set_theme()
sns.set_style('dark')

sigma_plot_values = np.linspace(1, 2.8, num=100)


fitted_line = hurdle(sigma_plot_values, beta0, beta1, gamma0, gamma1)
y_2016 = -4 + 5.35*sigma_plot_values


fig = plt.figure(figsize=(10,8), layout='constrained')
plt.xlim(1.0, 2.8)
plt.ylim(-0.5, 11)

plt.plot(sigma_plot_values, fitted_line, color='black')

ax = plt.gca()
        

ax.tick_params(reset=True, direction='in', top=False, right=False)
ax.minorticks_on()
ax.xaxis.set_major_locator(MultipleLocator(0.5))
ax.xaxis.set_major_formatter('{x:.1f}')
ax.xaxis.set_minor_locator(MultipleLocator(0.1))

plt.show()

For some reason, I can never get the minor ticks to show. Here is what I obtain

enter image description here

I would simply like to have major ticks at every 0.5 and minor ticks at every 0.1, but no matter what I try, they never show.

0 Answers
Related