如何向matplotlib eventplot添加图例?

2024-04-24 22:47:22 发布

您现在位置:Python中文网/ 问答频道 /正文

有人知道如何在matplotlib的新打印类型eventplot中添加图例吗?在

我尝试过很多事情,但都没有成功,包括:

labels1 = ['red', 'green', 'blue', 'yellow', 'magenta', 'cyan']
ax2.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
              linelengths=linelengths1, orientation='vertical', label=labels1)
ax2.legend()

这些编辑是在示例代码eventplot上进行的_演示.py发现于 http://matplotlib.org/dev/api/pyplot_api.html#matplotlib.pyplot.eventplot


Tags: api类型matplotlibgreenbluered事情图例
1条回答
网友
1楼 · 发布于 2024-04-24 22:47:22

TL;DR

只是,ax.legend( list_of_names )

解释

从你的密码里

labels1 = ['red', 'green', 'blue', 'yellow', 'magenta', 'cyan']
ax2.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1,
              linelengths=linelengths1, orientation='vertical')
ax2.legend( labels1 )

例如matplotlib.pyplot.eventplot中的示例

^{pr2}$

最终结果

Final result

相关问题 更多 >