我正在与分校的二级轴线合作:
fig, ax = plt.subplots()
ax.plot(range(1, 360, 5), range(1, 360, 5))
ax.set_xlabel( frequency [Hz] )
def invert(x):
# 1/x with special treatment of x == 0
x = np.array(x).astype(float)
near_zero = np.isclose(x, 0)
x[near_zero] = np.inf
x[~near_zero] = 1 / x[~near_zero]
return x
ax.set_xlim(left=1,right=360)
ax.set_xticks(np.linspace(0,360,10))
secax = ax.secondary_xaxis( top , functions=(invert, invert))
secax.set_xticks(1/np.linspace(1,360,5))
secax.set_xlabel( Period [s] )
#secax.set_xscale( log )
plt.show()
当我确定左侧=1时,出现以下错误:
ValueError: Axis limits cannot be NaN or Inf
我测试了将x_lim改为:
ax.set_xlim(right=360)
正确的数字是: