问题
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