0
使用我想一个令pColor剧情添加到比原来的脚本时,这里给出http://matplotlib.org/examples/mplot3d/2dcollections3d_demo.htmlmatplotlib令pColor为“3D 2D情节”
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
x = np.linspace(0, 1, 100)
y = np.sin(x * 2 * np.pi)/2 + 0.5
ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z')
colors = ('r', 'g', 'b', 'k')
for c in colors:
x = np.random.sample(20)
y = np.random.sample(20)
ax.scatter(x, y, 0, zdir='y', c=c)
xc = np.linspace(0, 1, 100)
yc = np.linspace(0, 1, 100)
fc = np.random.random((len(xc),len(yc)))
ax.pcolor(xc,yc,fc, zdir = 'x')
ax.legend()
ax.set_xlim3d(0, 1)
ax.set_ylim3d(0, 1)
ax.set_zlim3d(0, 1)
plt.show()
只是一些新行示例代码时不工作。不幸的是,它并不好,我真的不明白为什么。
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/figure.py", line 1159, in draw
func(*args)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 271, in draw
for col in self.collections]
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 271, in <listcomp>
for col in self.collections]
AttributeError: 'PolyCollection' object has no attribute 'do_3d_projection'
谢谢大家的支持。
感谢您的贡献,但这不是我正在寻找的。我会更好地解释。如果您尝试matplotlib网站中的示例脚本,您会看到ax.plot和ax.scatter被绘制为三维坐标平面上的投影。我也想为ax.pcolor做这件事(而不是像你建议的那样使用一个新图形)。 –