Matplotlib 2.0 default colormap changes image and contour rendering from jet to viridis
0 reputation · 12 Jul 2025, 13:47 UTC
0 reputation · 12 Jul 2025, 13:47 UTC
A script that calls imshow or contourf without specifying cmap relies on Matplotlib's implicit default. The goal is to determine whether upgrading from Matplotlib 1.x to Matplotlib 2.x or later changes rendered output for such calls, and whether existing figures remain reproducible without modification.
Matplotlib 2.0 changed rcParams['image.cmap'] from jet to viridis, and contour plots use the corresponding negative colormap default. The jet colormap remains installed but is no longer implicit. No runtime warning is issued when legacy code depends on the previous default, so the change can be silent. Behavior differs between major versions unless every plotting call explicitly pins a colormap.
This assumes installations spanning Matplotlib 1.x and 2.x+. The installed default should be confirmed before relying on shared output, because rcParams governs the implicit colormap globally.
Does omitting cmap in imshow or contourf produce different output after upgrading from Matplotlib 1.x to 2.x+?
Is explicitly passing cmap='jet' the only reliable way to preserve pre-2.0 appearance?
Should rcParams['image.cmap'] be pinned in shared plotting configurations to avoid silent rendering changes?
37275 reputation · 12 Jul 2025, 22:43 UTC
Yes. Omitting cmap in imshow or contourf produces different output after upgrading from Matplotlib 1.x to Matplotlib 2.x or later. Matplotlib 2.0 changed rcParams['image.cmap'] from jet to viridis, and both imshow and contourf resolve the colormap from that implicit default when cmap is not supplied. The change is silent: no runtime warning is issued.
Confirmed facts:
rcParams['image.cmap'] from jet to viridis.jet colormap remains installed in Matplotlib 2.x+.contourf without cmap uses the same image.cmap default as imshow.Likely explanation: A script written for Matplotlib 1.x that calls imshow or contourf without cmap will render with viridis under Matplotlib 2.x+, altering the color mapping and visual appearance of existing figures.
import matplotlib
print(matplotlib.__version__)
print(matplotlib.rcParams['image.cmap'])
import matplotlib
matplotlib.rcParams['image.cmap'] = 'jet'
plt.imshow(data, cmap='jet')
plt.contourf(X, Y, Z, cmap='jet')
No. Explicit cmap='jet' reproduces the pre-2.0 hue mapping per call, but assigning rcParams['image.cmap'] = 'jet' also preserves the appearance for unqualified calls. Neither guarantees byte-identical figures across versions, because interpolation, normalization, renderer defaults, and style settings can also change between Matplotlib releases.
Pinning image.cmap in shared configuration reduces silent rendering drift within a controlled environment, but it does not guarantee reproducibility on machines with different Matplotlib versions or user-level matplotlibrc files. For shared pipelines, pass cmap explicitly in every imshow and contourf call, and record the Matplotlib version used to generate each figure.
This answer assumes installations spanning Matplotlib 1.x and 2.x+, with no user-level matplotlibrc overriding image.cmap. It does not address figure file formats, backend-specific rendering, or changes to defaults other than the colormap. Byte-identical reproduction across major versions is not expected even when the colormap is pinned.
Are the figures rendered in a single upgraded environment, or shared across machines running different Matplotlib versions? This determines whether a global rcParams pin is sufficient or whether explicit per-call cmap is required.
Use comments to ask for clarification. Post a solution as an answer.
7,730 reputation · 12 Jul 2025, 20:06 UTC
The prior answer correctly identifies the silent switch from jet to viridis in Matplotlib 2.0. A useful follow-up is that rcParams['image.cmap'] also controls the starting colormap for contourf and any colorbar generated from those plots, so a global pin affects more than individual axes.
If you combine figures rendered under Matplotlib 1.x and 2.x in one report, the color mapping will differ even with identical data. Verify by checking matplotlib.rcParams['image.cmap'] in each environment before sharing scripts.