9951 explained code solutions for 126 technologies


python-matplotlibHow to change ticks to display inside the axes


In order to change axis labels frequency, we can use nbins option of locator_params to set the amount of ticks we want:

import matplotlib.pyplot as plt

plt.plot([2,1,3,5,3,3,4,5,2,1])
plt.tick_params(axis='x', direction='in')
plt.show()ctrl + c
import matplotlib.pyplot as plt

loads Matplotlib module to use plotting capabilities

.plot(

plot specified data

tick_params

set axis tick labels params

axis='x'

we want to update configuration for x axis only

direction='in'

display ticks inside the axis

.show()

render chart in a separate window