gpt4 book ai didi

python - 在 matplotlib 中,如何使单条线的线宽随 x 变化?

转载 作者:太空狗 更新时间:2023-10-29 22:27:41 26 4
gpt4 key购买 nike

有谁知道如何在 matplotlib 中使单条线的线宽随 x 变化?例如,对于较小的 x 值,您如何使一条线变细,而对于较大的 x 值,您如何使线变粗?

最佳答案

基本上,您需要使用多边形而不是直线。举个简单的例子:

import numpy as np
import matplotlib.pyplot as plt

# Make the original line...
x = np.linspace(0, 10, 100)
y = 2 * x
thickness = 0.5 * np.abs(np.sin(x) * np.cos(x))

plt.fill_between(x, y - thickness, y + thickness, color='blue')
plt.show()

enter image description here

或者,如果您想要更接近您的描述:

import numpy as np
import matplotlib.pyplot as plt

# Make the original line...
x = np.linspace(0, 10, 100)
y = np.cos(x)
thickness = 0.01 * x

plt.fill_between(x, y - thickness, y + thickness, color='blue')
plt.show()

enter image description here

关于python - 在 matplotlib 中,如何使单条线的线宽随 x 变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8172312/

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