我正在尝试在 matplotlib/python 中制作一个与此类似的居中气泡图。
有人称它为“底部对齐的气泡图”,至此,我基本上找到了一种同心圆散点图的方法。
%matplotlib inline
import matplotlib.pyplot as plt
s = [ 50000.,10478.2, 4733.4,3185.3,2484.7,2310.9]
x = [1]*len(s)
y = [0]*len(s);
plt.scatter(x,y,s=s);
plt.show()
关于如何排列这些同心圆的底部边缘有什么想法吗?
最佳答案
我会直接与 matplotlib 艺术家互动。我还将每个圆的半径(因此中心)设为人口的平方根。
这是因为,对于一个圆,A ~ r^2
,所以如果 r ~ population
,你会严重扭曲大小差异。
综上所述:
%matplotlib inline
import numpy
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
import seaborn
seaborn.set(style='white')
populations = numpy.sqrt([50000., 10478.2, 4733.4, 3185.3, 2484.7, 2310.9])
cp = seaborn.color_palette('Blues_r', n_colors=len(populations))
fig, ax = plt.subplots()
for n, p in enumerate(populations):
circle = plt.Circle((1, p), radius=p, facecolor=cp[n])
ax.add_artist(circle)
ax.set_xlim(-max(populations), max(populations))
ax.set_ylim(0, 2 * max(populations))
ax.set_aspect('equal')
plt.show()
给我这个:
关于python - 如何在 python/matplotlib 中制作居中气泡图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28863435/