如何在 Matplotlib 中更改阴影线的线宽?

matplotlibpythondata visualization更新于 2025/6/1 3:24:17

要更改 matplotlib 中阴影线的线宽,我们可以在参数中设置阴影线的线宽。

步骤

  • 设置图形大小并调整子图之间和周围的填充。
  • 使用 numpy 创建 x 和 y=sin(x) 数据点。
  • 设置图中阴影线的线宽。
  • 使用 scatter() 方法绘制 x 和 y 数据点,使用带有"/"阴影线的方形标记,并设置线宽。
  • 要显示图形,请使用 show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-5, 5, 25)
y = np.sin(x)
plt.rcParams['hatch.linewidth'] = 1
plt.scatter(x, y, s=700, marker='s', linewidth=0.05, facecolor='red',
hatch='/', alpha=.7)
plt.show()

输出


相关文章


有用资源