python - 结合图例图标 matplotlib
问题描述
我正在使用matplotlib在图例中显示一个带有单个图标的图和置信区间。过去我常写:
fig, ax1 = plt.subplots(1, 1)
curve = ax1.plot(...)
curve_fil = ax.fill_between(...)
fig.legend([(curve[0], curve_fill[0])], ["label here"], ...)
但是现在我收到以下错误:
TypeError: 'PolyCollection' object is not subscriptable
如果我删除[0]
并只提供情节作为参数,我会得到
AttributeError: 'NoneType' object has no attribute 'create_artists'
如果我尝试创建自定义补丁,例如:
patch = mpatches.Patch(color='r')
fig.legend([(curve[0], patch)], ["label here"])
然后我得到:
TypeError: 'Polygon' object is not subscriptable
这是什么意思呢?我开始在这个问题上扯掉我的头发......我知道已经发布了类似的问题,但是由于所有被标记为有效答案的建议对我都不起作用,所以我决定发布这个问题。
解决方案
推荐阅读
- javascript - 通过MVC更新JS模型不改变
- matplotlib - 如何以沿 x 轴共享共同比例的方式堆叠图形
- ms-access - Microsoft Access 数据库在表单中添加多行
- python - Groupby 大于 Pandas 非常慢
- laravel-5 - wkhtmltoimage: QsslSocket
- javascript - 我如何才能在最后一次调用后返回类方法结果
- linux - 如何使用 awk sed 或 shell 脚本组合两个不同的行
- java - 如何使用 java 流创建具有固定长度和特定数字的 int[]?
- android - 如何检查电话号码是否已存在于 Firebase 身份验证中?
- javascript - 如何使用 mongodb (node.js) 在集合中创建一个包含所有值的数组