python - 在子图中复制图例
问题描述
我试图将图例放在 2 个子图之外,fig.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
但图例仍在框中。我如何将这两个图例组合在框中并将其放在外面?
fig, (ax1, ax2) = plt.subplots(1, 2,sharey=True)
sns.lineplot(data=PopulationCensus2020.iloc[1:15,1:7],ax=ax1)
sns.lineplot(data=PopulationCensus2010.iloc[1:15,1:7],ax=ax2)
fig.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
for ax in fig.axes:
plt.sca(ax)
plt.xticks(rotation=45)
ax1.title.set_text('2020')
ax2.title.set_text('2010')
ax1.set_ylabel('Number of couples')
解决方案
推荐阅读
- python - 从python中的列表元素中删除字符
- java - 检查不重复的随机数
- android - 用于相机的具有透明度的矩形框
- mysql - MySQL 复制在 Master 上具有 NULL-able 列,在 Slave 上具有 NOT NULL
- rspec - Rails 5 Api 中的 rspec 控制器测试仍然很常见吗?
- python - Jupyter Notebook 不会输出
- python - 通过 id 计算从基线的变化
- visual-studio - Visual Studio 发布版本部署到 Hololens,但主版本没有 - 激活 Windows 应用商店失败
- java - 获取所有 DBpedia 资源的列表
- python-3.x - 在 python 中使用矩阵创建灰度图像