Změněné řádky jsou ty zakomentované s #old#
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
n_lines = 5
x = np.linspace(0, 10, 100)
y = np.sin(x[:, None] + np.pi * np.linspace(0, 1, n_lines))
c = np.arange(1, n_lines + 1)
#old# cmap = mpl.cm.get_cmap('jet', n_lines)
cmap = mpl.colormaps['jet'].resampled(n_lines)
fig, ax = plt.subplots(dpi=100)
dummie_cax = ax.scatter(c, c, c=c, cmap=cmap)
ax.cla()
for i, yi in enumerate(y.T):
ax.plot(x, yi, c=cmap(i))
#old# fig.colorbar(dummie_cax, ticks=c)
fig.colorbar(dummie_cax, ticks=c, ax=ax)
plt.show()