python - 如何在 python/matplotlib 中制作居中气泡图

标签 python pandas matplotlib visualization seaborn

我正在尝试在 matplotlib/python 中制作一个与此类似的居中气泡图。

enter image description here

有人称它为“底部对齐的气泡图”,至此,我基本上找到了一种同心圆散点图的方法。

%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()

给我这个:

enter image description here

关于python - 如何在 python/matplotlib 中制作居中气泡图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28863435/

相关文章:

python - 在 Google Colab 中编辑 README.md 文件

python - 用Python绘制时间频率

python - 我想在 csv 文件中搜索数据,其中数据取自 file1.csv 并使用 pandas 在 file2.csv 中搜索

python - 在 matplotlib 和 pandas 中组合和重新定位两个图表的图例的困难

python - 如何绘制非方形 Seaborn jointplot 或 JointGrid

python - 可迭代预期的原始文本文档,接收到字符串对象

python - 二维点的最小二乘拟合不通过对称轴

python - 根据条件合并 3 个不同的数据框

python - Matplotlib `` figure.titlesize`` rcParam

python - 使用 Python seaborn 绘制两侧分组条形图