我想创建一个3D散点图,将不同数据集放在同一个图中,并使用标签来表示它们。我面临的问题是无法正确添加图例,导致出现空标签的图形,就像这张图片一样:http://tinypic.com/view.php?pic=4jnm83&s=5#.Uqd-05GP-gQ。
更具体地说,我遇到了以下错误:
请查看下面一个我尝试过的示例演示:
更具体地说,我遇到了以下错误:
/usr/lib/pymodules/python2.7/matplotlib/legend.py:610: UserWarning: Legend does not support <mpl_toolkits.mplot3d.art3d.Patch3DCollection object at 0x3bf46d0>
Use proxy artist instead."
请查看下面一个我尝试过的示例演示:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import random
import csv
from os import listdir
from os.path import isfile, join
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
handles = []
colors = ['blue', 'red']
X1 = range(0,10)
Y1 = range(0,10)
Z1 = range(0,10)
random.shuffle(X1)
random.shuffle(Y1)
random.shuffle(Z1)
scatter1 = ax.scatter(X1, Y1, Z1, c = colors[0], marker = 'o')
random.shuffle(X1)
random.shuffle(Y1)
random.shuffle(Z1)
scatter2 = ax.scatter(X1, Y1, Z1, c = colors[1], marker = 'v')
ax.set_xlabel('X', fontsize = 10)
ax.set_ylabel('Y', fontsize = 10)
ax.set_zlabel('Z', fontsize = 10)
ax.legend([scatter1, scatter2], ['label1', 'label2'])
plt.show()
我看过其他类似的例子,但它们都没有使用scatter()图。除了一个可行的解决方案外,有人能解释一下我错在哪里吗?