Open Omer80 opened 6 years ago
From what I can tell, skimping over your example it will most likely be because matplotlib
doesn't handle the Color
objects returned from the brown.range_to
generator. You should try converting the Color
objects to strings before passing them into matplotlib:
cl = list(map(str, brown.range_to(Color("green"),3)))
Here's an example of how I made a colour range to fit to a plot of the Hilbert curve.
start_colour = Color("#000033")
end_colour = Color("#0000FF")
colour_range = list(start_colour.range_to(end_colour, len(distances)))
In the above, len(distances)
is the length of my Hilbert curve, so the number of colours in the range matches the number of line segments. I then wrote a loop which plots each line segment with the colour from the colour range. Note that you have to use str()
on the colour range list elements, as they are still Color objects, not strings.
plt.plot(xpoints, ypoints, c=str(colour_range[count]))
And the result:
Hi, I am trying to create a plot in which each line is picked from a colormap, like in this code:
How can I use colour package in order to create a custom gradient and use it with matplotlib? I tried to create a gradient from brown to green in this way:
But it gave me error when plugging cl to the code I've given above..