我正在python 2.7中绘制3d图
当我尝试使用2D plot()函数中的颜色和标记来绘制3d图时。我碰到一个错误。
因此,我尝试使用scatter()函数分别绘制线并使用标记分别测量点。
创建图例条目时,我的图例如下所示
但是我不想有重复的图例条目
我发现了与此类似的问题(如何在matplotlib中创建自定义图例),但不能解决我的问题
我要附加类似于我的问题的代码
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve 1')
ax.scatter(x, y, z, label='parametric curve 1',marker = 'o')
x = r * np.sin(theta + 1)
y = r * np.cos(theta + 1)
ax.plot(x, y, z, label='parametric curve 2')
ax.scatter(x, y, z, label='parametric curve 2',marker = 'o')
ax.legend()
plt.show()
上面的代码给了我下面的图
但我希望我的传说只有两个词条
您是否正在使用标准的Matplotlib库生成这些3D图?如果是这样,从文档中的示例(http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#line-plots)开始,它似乎可以正常工作:
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve 1', marker='o')
x = r * np.sin(theta + 1)
y = r * np.cos(theta + 1)
ax.plot(x, y, z, label='parametric curve 2', marker='o')
ax.legend()
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句