本文介绍了增加matplotlib中图例行的线宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,如果更改线的线宽,则会在图例中自动更新.但是,我只想更改图例的线宽而不影响绘图.
I know that if I change the linewidth of a line, that is automatically updated in the legend.However I would like to just change the legend linewidth without affecting the plot.
推荐答案
下面是一个简单的示例:
Here's a simple example of how to do it:
import numpy as np
import matplotlib.pyplot as plt
# make some data
x = np.linspace(0, 2*np.pi)
y1 = np.sin(x)
y2 = np.cos(x)
# plot sin(x) and cos(x)
p1 = plt.plot(x, y1, 'b-', linewidth=1.0)
p2 = plt.plot(x, y2, 'r-', linewidth=1.0)
# make a legend for both plots
leg = plt.legend([p1, p2], ['sin(x)', 'cos(x)'], loc=1)
# set the linewidth of each legend object
for legobj in leg.legendHandles:
legobj.set_linewidth(2.0)
plt.show()
这篇关于增加matplotlib中图例行的线宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!