1

I am currently using Matplotlib to batch plot 50+ graphs at a time from a single Python script.

From other users on StackOverflow, I've been able to find a way to control the font sizes globally, like so:

# SET FONT SIZES
size_xs = 8
size_s = 12
size_m = 16
size_l = 20
size_xl = 24

plt.rc("font", size=size_m)          # controls default text sizes
plt.rc("axes", titlesize=size_m)     # fontsize of the axes title
plt.rc("axes", labelsize=size_m)    # fontsize of the x and y labels
plt.rc("xtick", labelsize=size_m)    # fontsize of the tick labels
plt.rc("ytick", labelsize=size_m)    # fontsize of the tick labels
plt.rc("legend", fontsize=size_m)    # legend fontsize
plt.rc("figure", titlesize=size_m)  # fontsize of the figure title

# plt is short for matplotlib.pyplot

Is there a way to do the same and globally control the number of decimals displayed on the x and y axes? I have a mix of graphs plotted in both scalar and scientific notation, so a method that can work for both of these formats would be much appreciated.

  • 1
    Did you try anything at https://matplotlib.org/gallery/ticks_and_spines/tick-formatters.html – Jody Klymak Mar 20 '19 at 17:17
  • There is no way to set the number of decimal places globally in matplotlib. You can use some of the formatters available on a per case basis. For scientific notation this is especially hard, see [this question](https://stackoverflow.com/questions/25750170/can-i-show-decimal-places-and-scientific-notation-on-the-axis-of-a-matplotlib-pl/49330649#49330649). – ImportanceOfBeingErnest Mar 20 '19 at 21:20
  • @JodyKlymak, thank you for pointing me to the tick-formatters page on Matplotlib. I am very much a novice when it comes to programming, but I will experiment with the settings found on that page in due time. – TheEponymousProgrammer Mar 21 '19 at 22:18
  • @ImportanceOfBeingErnest, thank you for linking me to that question. It's a shame to learn that there is apparently no way of globally controlling the ticker format. Creating that MathText scientific notation ticker format is a workaround that suits my current work at the moment. – TheEponymousProgrammer Mar 21 '19 at 22:22

0 Answers0