gpt4 book ai didi

matplotlib - 具有可变标记大小的散点图(seaborn)

转载 作者:行者123 更新时间:2023-12-04 23:17:51 27 4
gpt4 key购买 nike

我正在使用seaborn pairplot绘制我的数据点不同维度的散点图。但是,我希望数据点的标记具有与数据点的维度之一相对应的大小。我有以下代码:

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不等。但是,图上的标记都是一样的。有什么办法可以实现我想要的吗?

顺便说一句,这与 lmplot 配合得很好。如果我设置参数 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)

enter image description here

关于matplotlib - 具有可变标记大小的散点图(seaborn),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35630749/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com