user1921464
user1921464

Reputation: 11

Overlap a heatmap in a 3d Matplotlib plot

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!

Upvotes: 1

Views: 941

Answers (1)

David Zwicker
David Zwicker

Reputation: 24278

Taken from the matplotlib examples:

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()

You can pass colors to the 3d-surface plot.

Upvotes: 1

Related Questions