标记大小可变的散点图(季节性) [英] Scatter plot with variable marker size (seaborn)
问题描述
我正在使用一个常见的 pairplot
绘制一个不同维度的数据点散点图。但是,我希望数据点的标记的大小与数据点的尺寸之一相对应。我有以下代码:
I am using a seaborn pairplot
to plot a scatter plot of different dimensions of my datapoints. However, I want the markers of the datapoints to have a size that corresponds to one of the dimensions of the datapoints. I have the following code:
markersize = 1000* my_dataframe['dim_size'] / sum(my_dataframe['dim_size'])
sns.set_context("notebook", font_scale=1.5, rc={'figure.figsize': [11, 8]})
sns.set_style("darkgrid", {"axes.facecolor": ".9"})
kws = dict(s=markersize, linewidth=.5, edgecolor="w")
sbax = sns.pairplot(my_dataframe, hue='dim_hue' x_vars=['dim_1', 'dim_2'], y_vars=['dim_3', 'dim_4'], size=5, plot_kws=kws)
axes = sbax.axes
for a in axes.flatten():
a.set_ylim([0,1])
a.set_xlim([0,1])
如果我做 print(kws)
,我会在字典中看到大小各不相同,从40到2000不等。但是,图中的标记都相同。有什么方法可以实现我想要的吗?
If I do print(kws)
, I see in the dictionary that the sizes are all different and vary from 40 to 2000. However, the markers on the plot are all the same. Is there any way to achieve what I want?
Btw,如果我设置了 lmplot
,效果很好参数 scatter_kws = { s:markersize}
。
Btw, this works very well with lmplot
if I set the parameter scatter_kws={"s": markersize}
.
谢谢!
推荐答案
import seaborn as sns
import matplotlib.pyplot as plt
iris = sns.load_dataset("iris")
size = 100 * (iris.petal_length / iris.petal_length.max())
g = sns.PairGrid(iris, vars=["sepal_length", "sepal_width"], size=5)
g.map(plt.scatter, s=size)
这篇关于标记大小可变的散点图(季节性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!