python scatter 三维曲面_使用Matplotlib中的scatter()在三维散点图中添加图例

我想创建一个三维散点图,在同一个图中包含不同的数据集,以及一个带有标签的图例。我面临的问题是,我无法正确添加图例,并且我得到了一个带有空标签的绘图,如图中所示:

更具体地说,我得到的错误是:/usr/lib/pymodules/python2.7/matplotlib/legend.py:610: UserWarning: Legend does not support

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()图。除了一个可行的解决方案,有人能解释我做错了什么吗?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值