gpt4 book ai didi

python - 在 Python 中绘制曲线

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:27 24 4
gpt4 key购买 nike

我想绘制特定拱形的曲线,下面是我使用特定值(需要使用这些值)的程度,但它绘制的是直线。

我也无法按照我想要的方式格式化 y 轴。这是一个对数刻度,我希望它达到 1(就像上面的理想图一样)。一些帮助会很好,谢谢! =)

最佳答案

您的线在对数比例图上没有拉伸(stretch)的原因是顶部和底部的点之间没有点。 log plot 没有曲线,只是将点放在不同的比例上,它们之间的线仍然是直线。

为了改变这一点,我们在点之间添加了更多的点。结果会变得弯曲。

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter

# Data for plotting
t = [0.0, 62.5, 125.0, 187.5, 250, 312.5, 375, 437.5, 500]
s = [0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1, 0.005, 0.1]

def extendlist(l):
master = []
for i in range(len(l)-1):
x = np.linspace(l[i], l[i+1], 50)
master.extend(x)
return master

t = extendlist(t)
s = extendlist(s)

fig, ax = plt.subplots()
ax.semilogy(t, s)

ax.set(xlabel='x axis', ylabel='y axis', title='Stuff')
plt.xlim((0,500))
plt.ylim((0.001, 1))

plt.show()

这将生成您在纸上绘制的图形。

enter image description here

关于python - 在 Python 中绘制曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55067307/

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