如何set_gid(),用于matplot散点图每个气泡?(How to set_gid() for

2019-10-17 16:33发布

我绘制散点图由以下代码:

import matplotlib.pyplot as plt

x = [2,4,6]
y = [1,3,7]
r = [650,890,320]
clr = ['r','b','g']
bubble_id = ['C0','C1','C2']

H0 = plt.scatter(x,y,s=r,c=clr)

然后我想'set_gid()'的三个气泡为'C0', 'C1' ,'C2'分别。 怎么做 ? 作为H0是一个单独的对象<matplotlib.collections.PathCollection object at 0x0ADA6D30> ,我不知道如何打破H0和H0找到的三个“水泡子”。 感谢您的提示。

Answer 1:

所以,我知道这可能不是最有效的解决方案,但如何循环?

import matplotlib.pyplot as plt
import itertools as it

X = [2,4,6]
Y = [1,3,7]
radius = [650,890,320]
clr = ['r','b','g']
bubble_id = ['C0','C1','C2']

ax = plt.subplot(111)
for x, y, r, c, id in it.izip(X, Y, radius, clr, bubble_id):
    ax.scatter(x,y,s=r,c=c, gid=id)

在视觉上给人同样的情节。

在IPython中我已经给看看PathCollection方法,它看起来像有非同小可的方式从中走出单一的补丁。



文章来源: How to set_gid() for each bubble in matplot scatter chart?