Home > Software design >  Turning up the lights in matplotlib
Turning up the lights in matplotlib

Time:05-19

I have the following Python code:

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams['figure.figsize'] = [12, 7]

n = 100
m = 100

X = np.arange(-n/2,n/2,1)
Y = np.arange(-m/2,m/2,1)
X, Y = np.meshgrid(X, Y)
    
landscape = np.exp(-0.01 * (X*X   Y*Y) )

fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.plot_surface(X, Y, landscape,
                linewidth=0,
                antialiased=False
                )

Running this in a notebook produces this image

enter image description here

If you look very closely you will see that the left-hand side of the Gaussian peak is very slightly lighter than the right-hand side. This lighting effect is barely visible, though, and I would like to increase it, so that the 3D shape becomes easily visible.

I'm aware of enter image description here

CodePudding user response:

You can use the cmap='Blues' parameter

ax.plot_surface(X, Y, landscape,
                linewidth=0,
                antialiased=False,
                cmap='Blues')

enter image description here

Or in reverse with cmap='Blues_r'

enter image description here

You can find all the colors in Choosing Colormaps in Matplotlib

  • Related