1

I have a histogram which has scientific notation of values along Y axis:

Histograms showing the amount pixels for a certain brightness value

The Channel B histogram has decimals along the Y axis. I want these numbers to be integers. I tried this solution, but once set_major_formatter is applied, the scientific notation is ruined, and then I cannot get it back since pyplot.ticklabel_format(axis = 'y', style = 'sci') raises AttributeError: This method only works with the ScalarFormatter. How can I prevent scientific notation from having decimals?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Kaiyakha
  • 1,463
  • 1
  • 6
  • 19

1 Answers1

1

I've found this solution offering MaxNLocator. It seems to work pretty fine if the amount of bins allows to keep ticks as integers. So for a simple plot it may go like this:

from matplotlib.ticker import MaxNLocator
# Some code
plt.gca().yaxis.set_major_locator(MaxNLocator(integer = True, nbins = 3))

The same can be applied to xaxis.

Kaiyakha
  • 1,463
  • 1
  • 6
  • 19