python - Seaborn 图调整“plotting_context”对于图例标记大小没有按预期工作
问题描述
我正在尝试调整 Seaborn 联合图中的图例标记。根据“MaozGelbart”在这个 Github issue上的回答,我希望rcParams
为此工作。配置在这里的 matplotib 文档中,我认为legend.markerscale
是我感兴趣的参数。
如何更改图例标记比例?下面的这段代码不起作用。但是,它确实适用于legend.fontsize
参数。
import pandas as pd
import seaborn as sns
d = {
'x': [3,2,5,1,1,0],
'y': [1,1,2,3,0,2],
'cat': ['a','a','a','b','b','b']
}
df = pd.DataFrame(d)
with sns.plotting_context(rc={"legend.fontsize": 'x-small', "legend.markerscale": 0.5}):
g = sns.jointplot(data=df, x='x', y='y', hue='cat')
这里有一个类似的Stack Overflow 问题,但似乎没有明确的答案。此外,rcParams
从理论上讲,设置应该有效
解决方案
根据Setting a fixed size for points in legend,调用.set_sizes([...])
图例句柄应该可以工作。
对于 ajointplot()
这将被称为:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
d = {'x': [3, 2, 5, 1, 1, 0],
'y': [1, 1, 2, 3, 0, 2],
'cat': ['a', 'a', 'a', 'b', 'b', 'b']}
df = pd.DataFrame(d)
with sns.plotting_context(rc={"legend.fontsize": 'x-large'}):
g = sns.jointplot(data=df, x='x', y='y', hue='cat')
for h in g.ax_joint.get_legend().legendHandles:
h.set_sizes([10])
plt.show()
推荐阅读
- javascript - 如何使用javascript导出带有输入字段的表格?
- php - 某些图像已损坏并在控制台中显示 508 错误
- node.js - NodeJS rest api,它返回类似于 Java Map 的响应,例如 Map
> - f# - 如何使用 Entity Framework Core 处理 F# 选项类型?
- linux - 如何使用 grep 命令复制单词匹配?
- angular - 作为输入传递的模板引用变量的类型是什么?
- python-3.x - Python 3.8 在写入文件时将所有字符串转换为变量
- python - 套接字客户端断开连接后,Python 线程保持活动状态
- ios - Apple 订阅或应用内购买在商店版本中不起作用 - 应用内产品详细信息未显示或获取
- python - 我想在程序开始时隐藏小部件