1

I am a newbie in matplotlib and I don't know where to look for that...

I want to plot data, where X and Y are parameters of a problem, then Z shows the resolution time for that problem with that parameters. But in the plot surface I want to show the hardness or the satisfiablility of the problem with a heatmap.

Is there any way for doing that?

Thanks!

4

1 回答 1

1

取自matplotlib 示例

from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
xlen = len(X)
Y = np.arange(-5, 5, 0.25)
ylen = len(Y)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)

colortuple = ('y', 'b')
colors = np.empty(X.shape, dtype=str)
for y in range(ylen):
    for x in range(xlen):
        colors[x, y] = colortuple[(x + y) % len(colortuple)]

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
        linewidth=0, antialiased=False)

ax.set_zlim3d(-1, 1)

ax.w_zaxis.set_major_locator(LinearLocator(6))

plt.show()

您可以将颜色传递给 3d 曲面图。

于 2012-12-21T12:20:02.233 回答