图例中的刻度大小符号 [英] Graduated size symbols in legends

查看:110
本文介绍了图例中的刻度大小符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经绘制了气泡图圆的大小对应于使用matplotlib的值列表.但是,我在为具有可变大小符号(对应于列出的大小)的绘图创建图例时遇到了麻烦.如上面链接中的一个.

I have plotted a bubble chart with the circles' sizes corresponding to a list of values using matplotlib. However, I'm having trouble creating a legend for the plot that has variable size symbols that corresponds to the listed size. Such as the one in the link above.

有没有一种方法可以在matplotlib中创建此图例而无需在绘图上手动绘制圆和文本?预先感谢您的时间和想法!

Is there a way to create this legend in matplotlib without manually drawing circles and text on the plot? Thanks in advance for your time and thoughts!

辛迪

推荐答案

是的,您可以具体说明要为哪些数据创建图例(选择说明性的大小)并在图例中指定其标签.

Yes, you can be specific about which data you make a legend for (choosing illustrative sizes) and specify their labels in the legend.

从此处的另一个分散式问题中的数据开始,然后将其中的一些遗忘在图例中(十字架):

Starting with data from one of the other scatter-legend questions here, and leaving some in that doesn't go into the legend (crosses):

import matplotlib.pyplot as plt
from numpy.random import random

colors = ['b', 'c', 'y', 'm', 'r']

ll = plt.scatter(random(10), random(10), s=10, marker='o', color=colors[0])
l  = plt.scatter(random(10), random(10), s=20, marker='o', color=colors[1])
a  = plt.scatter(random(10), random(10), s = 300, marker='o', color=colors[2])
z  = plt.scatter(random(10), random(10), s = 35, marker='+', color=colors[3]) # not in legend

plt.legend((ll, l, a),
       ('10', '20', '300'),
       scatterpoints=1,
       loc='lower left',
       ncol=1,
       fontsize=8)

plt.show()

要做的事情:将图例移出情节. (看起来您可能需要添加不可见的垂直间隔符.)

Left to do: moving the legend outside your plot. (And it looks like you might need to add invisible vertical spacers.)

这篇关于图例中的刻度大小符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆