How to set_gid() for each bubble in matplot scatter chart?

♀尐吖头ヾ 提交于 2019-12-11 10:09:48

问题


I draw a scatter chart by below codes:

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)

Then I want to 'set_gid()' to the three bubbles as 'C0', 'C1' ,'C2' respectively. How to do that ? As H0 is a single object <matplotlib.collections.PathCollection object at 0x0ADA6D30>, I don't know how to break down H0 and find the three 'bubble son' of H0 . Thanks for your tips.


回答1:


So, I know that might not be the most efficient solution, but what about looping?

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)

visually gives the same plot.

In Ipython I've given a look at PathCollection methods, and it looks like there is no trivial way to get out the single patches from it.



来源:https://stackoverflow.com/questions/14687089/how-to-set-gid-for-each-bubble-in-matplot-scatter-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!