sns.FacetGrid如何设置图例中图标的大小
时间: 2023-11-28 22:50:37 浏览: 70
要设置sns.FacetGrid图例中图标的大小,可以使用`plt.rcParams`来设置图例中图标的大小。具体操作如下:
1. 导入所需库和数据:
```python
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
```
2. 创建FacetGrid对象并绘制图形:
```python
g = sns.FacetGrid(tips, col="sex", hue="smoker")
g.map(sns.scatterplot, "total_bill", "tip", alpha=.7)
g.add_legend()
```
3. 使用`plt.rcParams`设置图例中图标的大小:
```python
plt.rcParams['legend.handlelength'] = 2.0
plt.rcParams['legend.markerscale'] = 2.0
```
完整代码如下:
```python
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="sex", hue="smoker")
g.map(sns.scatterplot, "total_bill", "tip", alpha=.7)
g.add_legend()
plt.rcParams['legend.handlelength'] = 2.0
plt.rcParams['legend.markerscale'] = 2.0
```
阅读全文