我试图做一个图,显示不同频谱的多普勒速度,但脚本似乎不喜欢我改变全局变量的事实。有没有办法解决这个问题?基本上,它只绘制全局变量的最新值的seonemic轴,见下图,顶部的一个甚至没有0。我猜它以某种方式追溯改变了以前的图。
之所以有一个glob,是因为我找不到一种方法来给予这个值,而不使secondary_xaxis函数崩溃。
的数据
最小工作示例:
def doppler(wavelengths):
c = 299792.458 # speed of light in km/s
lambda_0 = linecore # central wavelength in Angstrom
doppler_shifts = c * ((wavelengths-lambda_0) / lambda_0)
return doppler_shifts
def idoppler(doppler_shifts):
c = 299792.458 # speed of light in km/s
lambda_0 = linecore # central wavelength in Angstrom
wavelengths = lambda_0 * (1 + doppler_shifts / c)-linecore
return wavelengths
global linecore
plt.subplot(221)
plt.plot(np.linspace(-1,1,10)+6000, np.random.random([10]))
linecore = 6000
ax1 = plt.gca() # Get the current axis (i.e., the one just created)
ax1a = ax1.secondary_xaxis('top', functions=(doppler, idoppler))
ax1a.set_xticks([-50,0,50])
plt.subplot(222)
plt.plot(np.linspace(-1,1,10)+6000, np.random.random([10]))
linecore = 6000
ax2 = plt.gca() # Get the current axis (i.e., the one just created)
ax2a = ax2.secondary_xaxis('top', functions=(doppler, idoppler))
ax2a.set_xticks([-50,0,50])
plt.subplot(223)
plt.plot(np.linspace(-1,1,10)+8000, np.random.random([10]))
linecore = 8000
ax3 = plt.gca() # Get the current axis (i.e., the one just created)
ax3a = ax3.secondary_xaxis('top', functions=(doppler, idoppler))
ax3a.set_xticks([-50,0,50])
plt.subplot(224)
plt.plot(np.linspace(-1,1,10)+8000, np.random.random([10]))
linecore = 8000
ax4 = plt.gca() # Get the current axis (i.e., the one just created)
ax4a = ax4.secondary_xaxis('top', functions=(doppler, idoppler))
ax4a.set_xticks([-50,0,50])
plt.tight_layout()
plt.show()
字符串
1条答案
按热度按时间jvlzgdj91#
你应该用咖喱。
的数据
字符串