python - python - 使用 loc 重新定位我的图例
问题描述
这是我的代码的输出
如您所见,图例“pl”和“ppl”在右上角重叠。我如何让其中一个移动到左上角。我尝试搜索 ans,并使用“loc”来解决问题,但不知何故我继续出错。有人可以帮忙吗?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
ax1.set_xlabel('Date')
ax1.set_ylabel('percent change / 100')
dd = pd.DataFrame(np.random.randint(1,10,(30,2)),columns=['pl','ppl'])
dd['pl'].plot(ax=ax1,legend=True)
dd['ppl'].plot(ax=ax2, style=['g--', 'b--', 'r--'],legend=True)
ax2.set_ylabel('difference')
plt.show()
解决方案
推荐阅读
- jenkins - jenkins 会自动删除工作区的代码,然后每次重新拉代码来构建
- codeigniter - Codeigniter 只能显示默认控制器
- c# - Asp.Net Core WebApi:授权属性错误 403
- html - 我想从 iframe 中删除控件并向视频添加循环
- css - 如何排列固定和绝对定位的元素
- java - 列表
另一个列表的子集 忽略大小写? - selenium - 我正在尝试找出将从以下 HTML 中检索 img alt 文本的 XPath
- java - 如何在java中更新控制台输出?
- java - 未使用 Spring CommonsRequestLoggingFilter 记录响应内容
- javascript - javascript中的原型阴影和原型链接有什么区别