What might cause colors to differ between .png and .pdf output in Plots?

I just installed Ubuntu 20.04 on my work computer yesterday and have noticed that the colors in my Julia plots come out differently depending on whether I view them within VSCode/Jupyter, as a .png export, or as a .pdf export.

I’m not sure where in the stack the problem comes from, so I am posting here in hopes that someone has seen something similar. Is the issue most likely to be with Julia, Plots, Ubuntu, the Image Viewer Program in Ubuntu, my display configuration, or something else?

In my (limited) experience there are many things that have to go right before colors display correctly.

Here is some test code:

using Plots

plot(rand(200), c=:dodgerblue)


The plot displayed in VSCode looks like this.

Screenshot from 2021-08-10 11-21-01

test.png displayed in Image Viewer looks like this.

test.pdf displayed in Document Viewer looks like this.

  • Ubuntu version: 20.04
  • Julia version: 1.6.2
  • Plots version: 1.2.0
  • VSCode version: 1.59.0
  • Julia VSCode extension version: 1.3.27

I think the usual reasons are that different programs have different color management, so some respect color space information in image sources and some assume general properties which aren’t necessarily true. The different formats png and pdf could definitely have different color spaces, or maybe one of them had no color space information written to it and a generic space like the one you have set system wide is assumed.

Color differences usually present most clearly in saturated colors as those are at the edges of color spaces and are most affected by shifts.

I would try and look up programs with which you can query the color space information embedded into your files, and google if your programs are color managed or not.

1 Like

Why don’t you try uploading the “test.png” itself instead of the screenshot?

Assuming that those screenshots are properly managed in the sRGB color space, the colors in the PDF appear to be more “absolutely” accurate.

FWIW, I cannot reproduce the problem with the same versions, except that the OS is Windows 10.

Here’s test.png:

Hmm, it seems to look fine in my browser, which seems to locate the problem to VSCode and the image viewer (perhaps a common backend somewhere?).

1 Like

Just a thought, does this change at all if you zoom in? Sometomes resolution and aliasing effects can change the apparent color.

1 Like

The aliasing (as mentioned by @gustaphe) of the PNG can make the colors look different at certain magnifications:

But this might be in addition to any color management issues (mentioned by @jules).

Zoom experiments suggest that color management is the most likely culprit. But it seems odd that VSCode and the Ubuntu image viewer would have the same problem, unless they share a common backend, but then it would be weird for them to have a common backend not shared by Firefox.

Now that color management is widespread (even on Linux), color management problems often depend on having a consistent configuration, not on having a common backend.

Modern browsers such as Firefox and Chromium-based applications have their own color management systems. Usually, they refer to the profile settings of the OS or window manager, but for some reason they seem to be inconsistent.

Empirically, I guess the VSCode and the Ubuntu image viewer manage the colors to fit a wide gamut of color profiles (maybe properly), and Firefox does not. However, only you can know what colors are displayed on your display, so without profile data I cannot know what is ”correct". :sweat_smile:

Although it is almost impossible to determine if it is “correct” or not, you should be able to check if the OS profile settings are reflected in the application by changing the settings.