【问题标题】:seaborn scatterplot scale bubble size to larger dotsseaborn 散点图将气泡大小缩放为更大的点
【发布时间】:2020-05-14 04:04:28
【问题描述】:

我正在关注example,我想创建更大的气泡,但无论我将大小列乘以多大,它们仍然很小,是否有某种比例因子需要调整?我在文档中找不到它。

import seaborn as sns; sns.set()
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
ax = sns.scatterplot(x="total_bill", y="tip", data=tips)

cmap = sns.cubehelix_palette(dark=.3, light=.8, as_cmap=True)
ax = sns.scatterplot(x="total_bill", y="tip",
                     hue="size", size="size",
                     palette=cmap,
                     data=tips)

tips['size'] = 100 * tips['size']

ax = sns.scatterplot(x="total_bill", y="tip",
                     hue="size", size="size",
                     palette=cmap,
                     data=tips)

示例代码here

【问题讨论】:

  • 您链接到的文档有大约 20 个用于此目的的参数。因此,您有 20 分之一的机会选择正确的。

标签: python matplotlib seaborn


【解决方案1】:

显然,您还需要使用seaborn.scatterplot中的sizes参数来实现指定的大小范围。

minsize = min(tips['size'])
maxsize = max(tips['size'])
ax = sns.scatterplot(x="total_bill", y="tip",
                    hue="size", size="size", sizes=(minsize, maxsize),
                    palette=cmap,
                    data=tips)

【讨论】:

    【解决方案2】:

    感谢这个方法!效果很好。 在使用大量数据设置大尺寸无花果时,我遇到了同样的问题。 scatter 看起来很小,我无法区分大小。 所以首先设置元组,将其注入 sns.scatter

    顺便说一句,使用这种方法,您可以在 minsize 和 maxsize 上进行乘法运算,而无需更改大小的实际数据以及图例。我必须将 minsize 和 maxsize 设为五次方以使其可读!非常感谢!

    minsize = min(df['value'])**5
    maxsize = max(df['value'])**5
    fx= sns.scatterplot(x=df['this'], y=df['that'], data=df, hue=df['takeway'], size=df['value'], sizes=(minsize, maxsize), legend='brief')
    

    【讨论】:

      猜你喜欢
      • 2015-08-23
      • 2016-12-07
      • 1970-01-01
      • 2021-02-09
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2016-08-23
      • 2013-03-18
      相关资源
      最近更新 更多