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
On the Format tab, in the Current Selection group, click Format Selection. Under Axis Options, Click Number, and then in the Category box, select the number format that you want. Tip If the number format you select uses decimal places, you can specify them in the Decimal places box.
To remove the ticks on the y-axis, tick_params() method has an attribute named left and we can set its value to False and pass it as a parameter inside the tick_params() function. It removes the tick on the y-axis.
Type conversion in python helps to convert a decimal value number(floating number) to an integer. Thus converting float->int removes all decimals from a number.
Tick formatters can be set in one of two ways, either by passing a str or function to set_major_formatter or set_minor_formatter , or by creating an instance of one of the various Formatter classes and providing that to set_major_formatter or set_minor_formatter .
Convert the numbers into ints:
ax2.set_xticklabels(tick_labels.astype(int))
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