gpt4 book ai didi

python - Matplotlib:如何制作由点(圆圈)组成的虚线?

转载 作者:行者123 更新时间:2023-12-02 08:50:02 26 4
gpt4 key购买 nike

我有两个平滑依赖项 y1(x) 和 y2(x),其中 x 分布不规则。我希望用虚线(linestyle = ':')来描述这些依赖关系。我现在在 *.pdf 文件中得到的内容显示为 here :

代码如下:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

x = [0, 1, 2, 3, 5, 7, 13, 14]
y1 = [3, 5, 6, 8, 7, 6, 9, 10]
y2 = [1, 7, 8, 10, 14, 18, 20, 23]

ax.plot(x, y1,
linestyle = ':',
linewidth = 4,
color = 'Green')

ax.plot(x, y2,
linestyle = ':',
linewidth = 4,
color = 'Blue')

ax.set_ylabel('y(x)')
ax.set_xlabel('x')

plt.savefig("./test_dotted_line.pdf")

我使用了 dashes = [2,2] (和其他组合)和 dash_capstyle = 'round',但结果看起来很糟糕。

是否有可能出现由“圆”点组成的虚线?

最佳答案

试试这个线条样式:

ax.plot(x, y1, 
linestyle = (0,(0.1,2)),
dash_capstyle = 'round',
linewidth = 4,
color = 'Green')

输出是这样的: output

关于python - Matplotlib:如何制作由点(圆圈)组成的虚线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38849258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com