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

标签 matplotlib visualization data-visualization seaborn

我正在使用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/

相关文章:

在二维平面上可视化图表的算法?

r - 如何在与 `bquote` 一起使用的 `text` 表达式中换行?

python - Matplotlib:循环中的绘图在循环结束时再次出现

python - 我应该在 IPython 中的哪里添加 c.InlineBackend.rc = {} 以使用我自己的 matplotlib rc

debugging - 英特尔AT&T汇编程序的分步执行?

javascript - 如何将 Highcharts 折线图从简单的 html 转移到 Flask?

javascript - 将多维数组中的 HTML 表格与数据驱动文档分组

python - Matplotlib path.contains_points 对某些边上的点返回 false 而对其他边不返回

matplotlib - Jupyter 笔记本 matplotlib 数字显示很小,直到单元格完成

python - 有没有工具可以可视化 Python 中的方法调用?