python在scatter中添加图例,在Matplotlib中使用scatter()在3D散点图中添加图例

本文介绍了如何在Python的Matplotlib库中为3D散点图添加图例。作者遇到的问题是在尝试添加图例时遇到了警告,并提供了错误代码示例。解决方案是使用代理艺术家(proxy artist),创建Line2D对象来模拟散点图的特性,然后添加到图例中。通过设置'numpoints'为1和'linestyle'为'none',确保图例只显示一个点且不绘制线条。
摘要由CSDN通过智能技术生成

I want to create a 3D scatterplot with different datasets in the same plot and a legend with their labels. The problem I am facing is that I cannot properly add the legend and I get a plot with an empty label as the figure in:

More specifically, I get the error:

/usr/lib/pymodules/python2.7/matplotlib/legend.py:610: UserWarning: Legend does not support

Use proxy artist instead."

Please find below an example demo of what I have tried so far:

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 =

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值