我有一个情节:
但我希望刻度线位于零轴上(如在普通图形中那样......)。 我见过this example和this example,但我遇到了问题:
如果我尝试:
import matplotlib.pyplot as plt
import numpy as np
def f(t):
A = 2409.505
rho = 0.3260
C = 0.00
if C == 0.0:
return (A*np.exp(-t/rho))
else:
return (A*np.exp(-t/rho)) - (C/r**6)
t1 = np.arange(0, 15, 0.01)
plt.xlim(-1, 16)
plt.ylim(-500, 2500)
plt.spines['left'].setposition('0')
plt.spines['bottom'].setposition('0')
plt.plot(t1, f(t1), 'b', linewidth = '1.5')
plt.tick_params(top = 'off', right = 'off')
plt.grid(linestyle = '--', linewidth = 0.05)
plt.show()
我收到错误:
Traceback (most recent call last):
File "C:\Users\Rebecca\Downloads\pyplot_simple.py", line 16, in <module>
plt.spines['left'].setposition('0')
AttributeError: 'module' object has no attribute 'spines'
如果我尝试:
import matplotlib.pyplot as plt
import numpy as np
def f(t):
A = 2409.505
rho = 0.3260
C = 0.00
if C == 0.0:
return (A*np.exp(-t/rho))
else:
return (A*np.exp(-t/rho)) - (C/r**6)
t1 = np.arange(0, 15, 0.01)
plt.xlim(-1, 16)
plt.ylim(-500, 2500)
plt.axis['xzero'].set_axisline_style('-')
plt.axis['xzero'].set_visible(True)
plt.spines['bottom'].setposition('0')
plt.plot(t1, f(t1), 'b', linewidth = '1.5')
plt.tick_params(top = 'off', right = 'off')
plt.grid(linestyle = '--', linewidth = 0.05)
plt.show()
我收到错误:
Traceback (most recent call last):
File "C:\Users\Rebecca\Downloads\pyplot_simple.py", line 16, in <module>
plt.axis['xzero'].set_axisline_style('-')
TypeError: 'function' object is not subscriptable
我真的很困惑,我毫不怀疑,我再一次错过了一些非常明显的东西,所以任何帮助都会非常感激地收到 干杯
答案 0 :(得分:5)
试试这个:
plt.gca().spines['bottom'].set_position(('data',0))