python - 如何修改 Matplotlib 图例

标签 python python-3.x matplotlib

这是我的代码。

import numpy as np
from matplotlib import pyplot as plt

fig = plt.figure()

plt.plot(np.arange(0.0,12.0,2.0), 'r-', label='P = increasing')
plt.plot(np.arange(10.0,0.5,-1.8), 'g-', label='P = decreasing')


plt.legend()
plt.show()

输出如下图所示, enter image description here

但我想修改图例,以便它可以显示为, enter image description here

如何做到这一点?

最佳答案

你可以尝试:

plt.legend(markerfirst = False)

来自文档:

markerfirst : bool

If True, legend marker is placed to the left of the legend label. If False, legend marker is placed to the right of the legend label. Default is True.

关于python - 如何修改 Matplotlib 图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50916067/

相关文章:

python - 如何将 python 静态库与我的 C++ 程序链接

python pandas 日期 read_table

python - 在 AudioLazy 库中从 python 中的 zfilter 对象中提取数值

python - 在使用 seaborn 绘图分配斧头对象时遇到问题

python - 为什么我的程序卡在线程上?

python - 如何调整我当前的启动画面以允许我的其他代码片段在后台运行?

Python 请求 422 post 错误

python - 将 python 2 检查哈希转换为 python 3

python - 如何在 python 中将字符串数组传递给 fastapi

python - matplotlib:如何返回一个 matplotlib 对象然后作为子图绘制?