【问题标题】:How to make a centered bubble chart in python/matplot lib如何在 python/matplotlib 中制作居中气泡图
【发布时间】:2023-03-30 06:17:01
【问题描述】:

我正在尝试在 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()

关于如何排列这些同心圆的底部边缘的任何想法?

【问题讨论】:

  • 这是一个散点图,为每个点设置了大小,每个点都绘制在比公共底点高一个半径的地方。到目前为止,您尝试过什么?
  • 不知道为什么这个问题被搁置......在这里查看我的答案:gist.github.com/wmvanvliet/73b821746e401f9ba935

标签: python pandas matplotlib visualization seaborn


【解决方案1】:

我会直接与 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()

给我这个:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2015-08-22
    • 2015-05-06
    相关资源
    最近更新 更多