matplotlib ScalarFormatter interfering between figures

matplotlib.ticker.ScalarFormatter configures the colorbar and axes labels to not have too many decimal places.

ScalarFormatter Problem

If I made a standard line plot using the ScalarFormatter passed into a function, then subsequently passed the ScalarFormatter into another function that used colorbar, the line plot y-axis would be reset to match the limits of the later figure’s colorbar.

I didn’t think the ScalarFormatter would be able to feedback like that.

Fix ScalarFormatter interfering between figures

Enclose the ScalarFormatter in its own function, then call that function from each of the plotting functions, thereby creating a new/unique ScalarFormatter for each figure.

Leave a Comment