Home > Visualization > Main text

Bubble plot


Tag: plot, visualization

bubble plot可以结合展示三个变量之间的关系,本文主要是演练了这里这里的代码:

# create data
x = np.random.rand(5)
y = np.random.rand(5)
z = np.random.rand(5)

控制bubble的颜色、透明度:

# Change color with c and alpha
plt.scatter(x, y, s=z*4000, c="red", alpha=0.4)


控制bubble的形状:

plt.scatter(x, y, s=z*4000, marker="D")


控制bubble的大小:

plt.scatter(x, y, s=z*200)


控制bubble的边缘(线条粗细等):

plt.scatter(x, y, s=z*4000, c="green", alpha=0.4, linewidth=6)


先导入seaborn,则采用seaborn的主题:

import seaborn as sns
plt.scatter(x, y, s=z*4000, c="green", alpha=0.4, linewidth=6)



同时给气泡上颜色和大小,相当于展示了4个变量:

# create data
x = np.random.rand(15)
y = x+np.random.rand(15)
z = x+np.random.rand(15)
z=z*z
 
# Change color with c and alpha. I map the color to the X axis value.
plt.scatter(x, y, s=z*2000, c=x, cmap="Blues", alpha=0.4, edgecolors="grey", linewidth=2)

### plot color bar
### https://stackoverflow.com/questions/6063876/matplotlib-colorbar-for-scatter
sc = plt.scatter(x, y, s=z*2000, c=x, cmap="Blues", alpha=0.4, edgecolors="grey", linewidth=2)
plt.colorbar(sc)


If you link this blog, please refer to this page, thanks!
Post link:https://tsinghua-gongjing.github.io/posts/bubbleplot.html

Previous: Algorithm: 动态规划算法与最长公共子串