Massyanya
Massyanya

Reputation: 2934

Matplotlib: coloring line plots by iteration-dependent (non-gray) colour scale

I would like to make a plot with the pairs of trajectories that closely follow each other, here is how they currently look: enter image description here

I would like less recent pairs of trajectories to be lighter in shade, and more recent ones darker in shade.

One of them could go through the gray palette like in this advice, however as there has to be a pair of these and I want to be able to distinguish between the two, I need a way to rotate through the shades of yet another colour (a single colour, not the default multi-colour rotation matplotlib uses).

Does anyone has any ideas how to do that?

Upvotes: 0

Views: 110

Answers (1)

Gerges
Gerges

Reputation: 6499

You can use a color map. A list of available colormaps is available here: https://matplotlib.org/examples/color/colormaps_reference.html

Once you choose your colormaps you can use:

cmap1 = plt.cm.get_cmap('Reds')
cmap2 = plt.cm.get_cmap('Blues')

Then, you can select a color by color1 = cmap1(t). note that t must be between 0 and 1, so if it is not, you must shift it and scale. If you know your min and max times, you can use the Normalize class:

norm = mpl.colors.Normalize(vmin=tmin, vmax=tmax)
color1 = cmap1(norm(t))

Upvotes: 1

Related Questions