colored wireframe plot in matplotlib

一曲冷凌霜 提交于 2019-12-03 23:21:26

When you use plot_wireframe, each line can only have one color. Instead, you can use plot_surface. To get plot_surface to set the edgecolors, you need to give it facecolors. Then you can set the alpha of facecolors to zero.

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

X, Y, Z = axes3d.get_test_data(0.2)

# Normalize to [0,1]
norm = plt.Normalize(Z.min(), Z.max())
colors = cm.viridis(norm(Z))
rcount, ccount, _ = colors.shape

fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rcount=rcount, ccount=ccount,
                       facecolors=colors, shade=False)
surf.set_facecolor((0,0,0,0))
plt.show()

Maybe you need to use plot_surface instead?

import matplotlib.pylab as plt
from matplotlib import cm 
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize=(8, 8))
ax = fig.gca(projection='3d')

t = np.linspace(-3, 2, 31)
s = np.linspace(-3, 2, 31)

T, S = np.meshgrid(t, s)

ax.plot_surface(T * T, sqrt2 * T * S, S * S, cmap=cm.jet, rstride=1, cstride=1)

ax.set_xlabel('$t^2$')
ax.set_ylabel('$\sqrt{2} s t$')
ax.set_zlabel('$s^2$')

ax.set_title('line $s = t$ in $\cal F$')

plt.show()

I had a similar problem with coloring and sizing circles according to a variable which did not work either. So my workaround was to bin the values of the variables and loop over the bins. I masked the data such that the array mask did only contain the data with values in that bin.

ax.plot_wireframe(mask[i], ..., color="red")
ax.plot_wireframe(mask[i], ..., color="blue") 
etc.

I know it's not very elegant but in my case it did the job ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!