【发布时间】:2023-03-24 00:48:01
【问题描述】:
我必须在 x 轴上以对数刻度在 python 中显示带有matplotlib 的函数图,我想知道是否有可能显示x=0?我知道没有log(0)...
from matplotlib import pyplot as plt
def fkt(x,e):
y=np.sin(1/(x+e))
return y
def bild_fkt():
"""plottet die Funktion im Intervall[0,1] mit epsilon=1/5, 1/10, 1/20 mit linearer und
logarithmischer Skala """
plt.figure(figsize=(10,10))
x=np.linspace(0,1,100)
plt.subplot(211) #plots on linear scale
plt.plot(x, fkt(x,1/5), 'r', lw=2, label='e=1/5')
plt.plot(x, fkt(x,1/10), '-.', color='b', label='e=1/10')
plt.plot(x, fkt(x,1/20), ':', color='g', label='e=1/20')
plt.legend(loc=4)
plt.grid()
y=np.logspace(0,0.3010299957,100) #plots on logarithmic scale
plt.subplot(212)
plt.plot(y-1, fkt(y-1,1/5), 'r', lw=2, label='e=1/5')
plt.plot(y-1, fkt(y-1,1/10), '-.', color='b', label='e=1/10')
plt.plot(y-1, fkt(y-1,1/20), ':', color='g', label='e=1/20')
plt.legend(loc=4)
plt.grid()
plt.semilogx()
bild_fkt()
【问题讨论】:
-
y轴上的刻度是多少?你说f(x) = 0,好像是y = 0的意思。 -
哦,你是对的。在 y 轴上我想使用线性刻度,在 x 轴对数刻度上。我想说的是 x=0
-
log(0)未定义。所以不可能在图表上绘制它。不过,将0放在轴上是另一回事。 -
好吧,显然不是。当您在
x-axis上靠近x = 0时,值会越来越小,趋向于0,但从未达到它。在线性刻度上,我认为中心是0,左边有负值,右边有正值。在对数刻度上,我认为中心是1,左边是小数值,右边是倍数。
标签: python python-3.x numpy matplotlib math