1
from matplotlib import pyplot as plt
import numpy as np
from matplotlib import colors
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap

color_list = [-18.975, -19.269, -19, -19, -20.739, -21.612, -21.409,
              -21.436, -22.022, -22.214, -21.482, -21.958, -20.562, -21.767]

x = np.random.random(14)
y = np.random.random(14)
z = np.random.randint(-2, 3, 20)

cmap = plt.cm.RdBu
norm = colors.BoundaryNorm(np.arange(-23, -18, 0.5), cmap.N)

plt.scatter(x, y, c=color_list, cmap=cmap, norm=norm, s=100, edgecolor='none')
plt.colorbar(ticks=np.linspace(-18, -23, 10))
plt.show()

resulting plot

I want to reproduce the exact same functionality but for a normal plt.plot() line plot. I have a plot with 14 lines and want to color each line of this plot depending on the value from the color_list. So in principle just replace the coloured dots with lines. The colormap / colorbar should be discretized as well.

albireo
  • 11
  • 2

0 Answers0