Skip to content
Advertisement

How can I remove digits after decimal in axis ticks in matplotlib?

I have

tick_location = np.linspace(0.01, 10, num=10, endpoint=True)
ax2.set_xticks(tick_location)
tick_labels = np.around(1/new_tick_loc*1e4,decimals=-2)
ax2.set_xticklabels(tick_labels)

This (and some additional code) produces the following plot, but I’d like to remove the decimal point and the digit after it from the tick labels on the top x axis.

Using matplotlib.ticker.FormatStrFormatter(fmt) does not help

top x axis with decimal

Advertisement

Answer

Convert the numbers into ints:

ax2.set_xticklabels(tick_labels.astype(int))
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement