1

Is there any way in matplotlib that I can specify the number of digits to be used in the tick labels of an axis when there is a common exponent?

To be more specific, I have ticks on y-axis at [-3e-5, 0.0, 3e-5], and I want the label to be shown as -3.0, 0.0, 3.0 with the common factor 1e-5 shown at the top left outside. My matplotlib sets these labels as -3, 0, and 3 by omitting .0 from the string.

I tried using matplotlib.ticker.FormatStrFormatter as in this answer, A. Matplotlib: Specify format of floats for tick lables

like,

ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))

but then I can't get the common factor 1e-5.

I tried using

matplotlib.ticker.ScalarFormatter(useOffset=True)

to get the common factor, but then it looks I can specify the number of digits to be shown.

I would appreciate any help.

norio
  • 3,652
  • 3
  • 25
  • 33
  • 1
    You will want to use the `FormatScalarFormatter` I invented in [this answer](https://stackoverflow.com/a/45816969/4124317) and apply it to your axis. `ax.yaxis.set_major_formatter(FormatScalarFormatter("%.1f"))`. If you have a problem with implementation, a complete code would be needed. – ImportanceOfBeingErnest Nov 17 '18 at 11:25
  • 1
    If you also want to fix the offset, see [this question](https://stackoverflow.com/questions/42656139/set-scientific-notation-with-fixed-exponent-and-significant-digits-for-multiple). – ImportanceOfBeingErnest Nov 17 '18 at 11:35

0 Answers0