Skip to content Skip to sidebar Skip to footer

Color Map To Shades Of Blue - Python

I have the following (example) code: 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] + n

Solution 1:

You need to change your colormap that you are using from jet to Blues.

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)

norm = mpl.colors.Normalize(vmin=c.min(), vmax=c.max())
cmap = mpl.cm.ScalarMappable(norm=norm, cmap=mpl.cm.Blues)
cmap.set_array([])

fig, ax = plt.subplots(dpi=100)
for i, yi inenumerate(y.T):
   ax.plot(x, yi, c=cmap.to_rgba(i + 1))
fig.colorbar(cmap, ticks=c)
plt.show()

This produces:

enter image description here

Post a Comment for "Color Map To Shades Of Blue - Python"