如何在 Matplotlib 中在 Seaborn 线图上绘制虚线?
matplotlibpythondata visualization更新于 2025/6/1 8:12:17
要在 Seaborn 线图上绘制虚线,我们可以在 lineplot() 的参数中使用 linestyle="dashed"。
步骤
设置图形大小并调整子图之间和周围的填充。
使用 numpy 创建 x 和 y 数据点。
使用 lineplot() 方法,在参数中使用 x 和 y 数据点,并使用 linestyle="dashed"。
要显示图形,请使用 show()方法。
示例
import seaborn as sns 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.random.rand(10) y = np.random.rand(10) ax = sns.lineplot(x=x, y=y, linestyle="dashed") plt.show()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

