matplotlib中线宽linewidth的默认值是多少?如何查看?如何设置/设定?如何修改?

绘图

使用下边的代码绘图:

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0.0, 2.0, 0.02)
y1 = np.sin(2 * np.pi * x)
y2 = np.exp(-x)
line1, = plt.plot(x, y1)
line2, = plt.plot(x, y2)

绘制结果如下图所示:
在这里插入图片描述

读取线宽

使用下边的代码,读取线宽linewidth的默认值,发现默认值是1.5

line1.get_lw()

修改线宽

使用下边的代码,将线宽linewidth设置为5

line1.set_lw(5)

如图下图所示,修改后线宽明显变大了。
在这里插入图片描述

修改线宽的第二种方法

plt.plot(x, y1, lw=2)

像上边这样直接在绘图时候设置好线宽即可

两种修改线宽方法的区别

line1.set_lw(5)

使用上边这种方法修改线宽的话,可以在图片绘制好了之后做调整,很方便后期修改

plt.plot(x, y1, lw=2)

使用上边这种方法修改线宽的话,只能在绘图的同时进行设置,后期修改的话需要重新绘图

要根据自己的需要选择合适的方法。

see also

  1. https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#
  2. https://matplotlib.org/stable/gallery/misc/set_and_get.html#
  3. https://matplotlib.org/stable/api/_as_gen/matplotlib.lines.Line2D.html#
  4. https://matplotlib.org/stable/gallery/text_labels_and_annotations/figlegend_demo.html#figure-legend-demo

おすすめ

転載: blog.csdn.net/shiyuzuxiaqianli/article/details/121251285
おすすめ