在sns散点图中更改图例

问题描述

我正在使用seaborn的散点图创建以下可视化效果:

enter image description here

sns.scatterplot(x="page",y="length",hue="% of marginal annotations",size="% of marginal annotations",legend="brief",data=df,palette = cmap,s=40,alpha=.6,sizes=(20,200)).set(xlabel='Folio number',ylabel='Length')

设置为“简短”时,图例会将数据分解为从0到... 120的40%增量!我担心这个传说会误导读者,使我认为我的某些数据点超过100%(从来没有这样)。如何更改图例,使其显示从0到100%的不同大小?

解决方法

如果您确信自己的"% of marginal annotations"数据点中没有一个超过100%,则只需添加.legend(range(0,125,25)),本质上就是定义图例中应包含哪些值。

fig,ax = plt.subplots()
ax = sns.scatterplot(x="page",y="length",hue="% of marginal annotations",size="% of marginal annotations",legend="brief",data=df,palette = cmap,s=40,alpha=.6,sizes=(20,200))
ax.set(xlabel='Folio number',ylabel='Length')
ax.legend(range(0,25))

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...