租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

Matplotlib中怎么自定义图例填充样式,matplotlib怎么用

发布时间:2024-05-11 17:20:50

Matplotlib中怎样自定义图例填充样式

要自定义图例填充样式,可使用 legend 函数的 facecolor 参数来指定填充色彩。下面是一个示例代码:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

plt.plot(x, y, label='Line')
plt.legend(facecolor='lightblue')

plt.show()

在上面的示例中,我们使用 plt.legend(facecolor='lightblue') 来设置图例的填充色为浅蓝色。您可以根据需要更改色彩或添加其他自定义样式。