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

**URL:** https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102
**Category:** Offtopic
**Tags:** plots
**Created:** [August 10, 2021, 2:37am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102 "2021-08-10T02:37:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [August 10, 2021, 2:37am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/1 "2021-08-10T02:37:50Z")

</div>

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:

```julia
using Plots

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

savefig("test.png")
savefig("test.pdf")

```

The plot displayed in VSCode looks like this.

![Screenshot from 2021-08-10 11-21-01](https://global.discourse-cdn.com/julialang/original/3X/1/2/12e4c604ee46c54dec7061655999f305881eeec8.png)

`test.png` displayed in Image Viewer looks like this.

 ![Screenshot from 2021-08-10 11-21-19](https://global.discourse-cdn.com/julialang/original/3X/2/5/256a7e94c0f79375433f2e796e618d97e9310287.png)

`test.pdf` displayed in Document Viewer looks like this.

 ![Screenshot from 2021-08-10 11-21-05](https://global.discourse-cdn.com/julialang/original/3X/7/b/7b9892cf4ebef4d5c06b2be81b8e7b9b4cb134f6.png)

- 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

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [August 10, 2021, 5:11am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/2 "2021-08-10T05:11:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [August 10, 2021, 5:24am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/3 "2021-08-10T05:24:57Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [August 10, 2021, 8:14am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/4 "2021-08-10T08:14:30Z")

</div>

Here’s `test.png`:  
 ![test](https://global.discourse-cdn.com/julialang/original/3X/0/5/054517d7cb9da27967ee1f6509ac9d707ccf6544.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?).

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [August 10, 2021, 10:00am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/5 "2021-08-10T10:00:21Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [August 10, 2021, 10:55am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/6 "2021-08-10T10:55:59Z")

</div>

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

 ![Screenshot 2021-08-10 at 11.50.07](https://global.discourse-cdn.com/julialang/original/3X/3/2/3238c72876b3b905e5fff8e14d4f173d1577812a.png)

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

---

<div class="post-metadata">

### Author: ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)
#### Post date: [August 11, 2021, 12:24am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/7 "2021-08-11T00:24:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [August 11, 2021, 3:38am UTC](https://discourse.julialang.org/t/what-might-cause-colors-to-differ-between-png-and-pdf-output-in-plots/66102/8 "2021-08-11T03:38:28Z")

</div>

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". 😅

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.  
[https://help.ubuntu.com/stable/ubuntu-help/color-testing.html.en](https://help.ubuntu.com/stable/ubuntu-help/color-testing.html.en)
