How to create custom color grading using PyPlot (not matplotlib)

Jobs at IJulia. Desperately trying to create a custom color palette. Tried the line:

matplotlib.colors.ListedColormap([(1,0,0),(0,1,0),(0,0,1)],"A") 

which led to the following error

The PyObject type does not have field colors when loading In [16], in the expression starting on line 1

which apparently means that I cannot use matplotlib directly, but only the functions that are in PyPlot.

I cannot enable matplotlib with import (since this is not valid in IJulia). I noted that others have helped in solving such problems, but this does not solve my problem.

+5
source share
2 answers

Using the PyCall package that PyPlot uses to transfer matplotlib, you can get the same color code:

 using PyCall @pyimport matplotlib.colors as matcolors cmap = matcolors.ListedColormap([(1,0,0),(0,1,0),(0,0,1)],"A") 

To access the fields in PyObject, you need to index the object with a symbol, for example:

 cmap[:set_over]((0,0,0)) 

This is equivalent to: cmap.set_over((0,0,0)) in python. For other good examples of plotting various types using PyPlot, see the following examples: https://gist.github.com/gizmaa/7214002

+3
source

You do not need to use PyCall to directly call Python (although this, of course, is an option). You can also simply use PyPlot constructors for PyPlot to build a color map from (r, g, b) arrays or an array of colors, as defined in the Julia Color package. See the PyPlot ColorMap Documentation. For instance:

 using PyPlot, Color ColorMap("A", [RGB(1,0,0),RGB(0,1,0),RGB(0,0,1)]) 
0
source

All Articles