0

Here is a Python code that creates a plot with 6 defined colors and saves it in a PNG file:

import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np

Define a colormap of 6 colors

palette = ['#0d0887', '#6a00a8', '#b12a90', '#e16462', '#fca636', '#f0f921'] my_cmap = mpl.colors.ListedColormap(palette)

Plot the 6 colors

a = np.arange(3*2).reshape(3,2) plt.pcolormesh(a, cmap=my_cmap)

Print hex colors

for i in range(my_cmap.N): rgba = my_cmap(i) # rgb2hex accepts rgb or rgba" print(f"'{mpl.colors.rgb2hex(rgba)}', ", end='')

Save figure

plt.savefig('test.png')

The plot created inside the Jupyter Notebook contains the correct colors, i.e. a color picker tool provides the same hex color values that are defined in the script.

colors in Jupyter Notebook

correct picked colors

However, when opening the saved PNG file with Eye of GNOME Image Viewer or Firefox, the colors values obtained with the picker tool are different:

colors in GNOME Image Viewer

wrong picked colors

Colors are correct when opening the file with Shotwell, Loupe (default image viewer replacing Eye of GNOME), or Chrome.

System information:

  • Ubuntu 24.04.1 LTS
  • GNOME Shell 46.0
TVG
  • 529

1 Answers1

1

Thanks to @BeastOfCaerbannog's help, here are solutions.

Solution for the default Ubuntu Image Viewer

Eye of GNOME (EoG) is no longer the default image viewer. It has been replaced by Loupe, which does not have any color issues.

To install Loupe, use the following command:

sudo apt install loupe

To remove EoG, use:

sudo apt remove eog

Solution for Firefox

Since version 3.5, Firefox applies color correction to some images. It is possible to disable this featute by entering about:config in the URL bar, searching for gfx.color_management.mode, and setting it's value to 0, as mentioned in the link below.

Note: This solution was found in this ~11-year-old post.

TVG
  • 529