Reputation: 11
I am running the below code to display the Z function. The output is supposed to come in color. However, it is displaying in grey-scale. This is in Jupyter notebook. It is showing in color when I run in other places.
# Import numpy and matplotlib.pyplot
import numpy as np
import matplotlib.pyplot as plt
# Generate two 1-D arrays: u, v
u = np.linspace(-2, 2, 41)
v = np.linspace(-1,1,21)
# Generate 2-D arrays from u and v: X, Y
X,Y = np.meshgrid(u,v)
# Compute Z based on X and Y
Z = np.sin(3*np.sqrt(X**2 + Y**2))
# Display the resulting image with pcolor()
plt.pcolor(Z)
plt.show()
Upvotes: 1
Views: 1602
Reputation: 2482
Besides setting the default colormap you can pass one directly to the pcolor
method:
from matplotlib import cm
plt.pcolor(Z, cmap = cm.viridis)
In a Jupyter notebook you can press TAB
after typing cm.
to see all available colormaps.
Upvotes: 2
Reputation: 11
I found that this is because the default color-map is 'Greys' for me. plt.rcParams['image.cmap']
results in 'Greys'.
I can set it to 'jet' which now shows the plots in color.
plt.rcParams['image.cmap'] = 'jet'
Upvotes: 0