On Fri, 16 May 2014, Eric Firing wrote: > On 2014/05/16 4:41 PM, Michael Goerz wrote: > >While playing around for an afternoon with colors in matplotlib, I came > >across some inconsistencies. I was trying to define colors in sRGB (my > >understanding is that sRGB as a standardized color space is > >device-independent). Giving RGB values to matplotlib, I checked the > >output with a color picker -- Color Maker from the Mac App Store, set > >to the sRGB mode, but the built-in DigitalColor Meter gives the same > >result. It turns out that the colors I see in the output are not what I > >specified. This makes playing around with colors, a bit difficult: > >http://nbviewer.ipython.org/gist/goerz/9aab94f5322d5a457625 > >As far as I can tell, Matplotlib does not specify in > >which color model in interprets RGB values (this should ideally be > >stated in the documentation). Also, the output in different backends > >(IPython notebook, and interactive GUI) gave different results. As a > >minimal example, consider the following: > Matplotlib doesn't interpret RGB values; that is left to the display > device. Matplotlib simply writes the RGB values in a file, > unmodified, or sends them via a GUI backend to a display, also > unmodified *by mpl*. What you put in, is what it puts out. > > Thanks for pointing out the DigitalColor Meter--I hadn't noticed it. > > What I see with your example is that the MacOSX backend *display* is > interpreting RGB as sRGB, and the qt4agg backend *display* is > interpreting RGB as native values (based on matching with > DigitalColor Meter). > > I haven't tried this with inline plots in the notebook, but mpl is > merely feeding RGB values to the browser, just as would occur when > displaying a png, and it is up to the browser to decide how to > convert them into pixel intensity. > > I don't see that there is a bug here. Fair enough, so that would imply that there is a difference between the png streams produced by matplotlib and the "direct" PIL image. I might be seeing the problems discussed here: https://hsivonen.fi/png-gamma/ It might be that the matplotlib png stream is "untagged", whereas the PIL image is tagged properly as sRGB. I'd have to decode the base64 data from the notebook to check this.
Beyond that it seems quite tricky to understands how in a given application, or matplotlib backend in this case, a given RGB color input yields a specific output on my screen, and how to make this consistent (consistency obviously being more important than accurateness with respect to some "real" color model). Maybe this just goes to show what I realized these last couple of days, that colors are a huge can of worms. > > import pylab > > import numpy as np > > import matplotlib > > #%matplotlib inline > > # draw line with sRGB color 228, 26, 28 > > pylab.plot(np.linspace(0,10, 10), np.linspace(0,20,10), linewidth=10, > > color=(0.894, 0.102, 0.110)) > > pylab.show() > > # Colorpicker shows 210, 46, 13 in GUI view > > # Colorpicker shows 229, 39, 27 in iPython Notebook > > > >In the IPython notebook, direct PIL graphics do seem to give the right > >colors cf. In [5] in the linked IPython notebook (even though PIL also > >does not explicitly specify its color model). Just matplotlib seems > >off. Of course, I'm doing some slightly crazy stuff in the Notebook, > >displaying every matplotlib output through PIL, but I cecked that > >`%matplotlib inline` actually produces the same colors. > > > >Should I file this on github as a bug report? > > > >Best, > >Michael > > > >P.S.: please CC for direct replies ------------------------------------------------------------------------------ "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users