3

Why do all points get the same value? I would like color to vary with energy.

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
from numpy import *

x = linspace(0.2, 2, 11)
y = linspace(0.1, 1, 11)
alpha, beta = meshgrid(x,y)
energy = matrix(loadtxt('energyPlotfileN6.txt'))

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(alpha, beta, energy, cmap='summer', vmin=energy.min(), vmax=energy.max())
plt.xlabel("alpha")
plt.ylabel("beta")
ax.set_zlabel("energy")
plt.show()

The result is shown below

Surface plot without desired colour mapping

2
  • 1
    Do you get the same output if you replace cmap='summer' with cmap=cm.summer? Commented May 23, 2016 at 17:44
  • Yes I do. @jonchar Commented May 23, 2016 at 17:46

2 Answers 2

2

Used the answer from above (add the cstride and rstride arguments), but wanted to add a visualization of the difference...

In my case I'm plotting terrain...

No stride:

surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'],
                       cmap='terrain', vmax=2800, vmin=1300,
                       linewidth=.1, antialiased=False)

enter image description here

With stride:

surf = ax.plot_surface(topo['lon'], topo['lat'], topo['value'],
                           cmap='terrain', vmax=2800, vmin=1300,
                           linewidth=.1, antialiased=False,
                           rstride=1, cstride=1)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1
ax.plot_surface(alpha, beta, energy, cstride=1, rstride=1, cmap='summer', vmin=energy.min(), vmax=energy.max())

Note the cstride and rstride parameters.

Axes3D.plot_surface documentation.

1 Comment

Amen to using the cstride and rstride parameters!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.