我想在两个x和y轴上绘制数据序列,以便拥有4个不同的轴。首先是x(能量,以电子伏特为单位)与y(标准化计数)轴,然后是x(波长,与能量成反比)与y(计数)轴。我的代码如下:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from scipy.constants import h, c, e
def E(wavelength):
return (h*c)/(wavelength*e)
wavelen = np.linspace(800e-9,1600e-9,200)
E_eV = E(wavelen)
loc, scale = 950e-9, 3.0
counts = mlab.normpdf(wavelen,950e-9,100e-9)/100
counts_norm = counts/10000
fig, ax = plt.subplots()
ax1 = ax
ax2 = ax.twinx()
ax3 = ax.twiny()
plt.ticklabel_format(style='sci', scilimits=(0,0))
ax1.plot(E_eV, counts_norm)
ax1.set_xlim(E(1600e-9),E(800e-9))
ax1.set_ylabel('normalized counts')
ax1.set_xlabel('energy (eV)')
ax2.plot(E_eV, counts)
ax2.set_xlim(E(1600e-9),E(800e-9))
ax2.set_ylabel('counts')
ax3.plot(wavelen*1e9, counts_norm)
ax3.set_xlim(1600,800)
ax3.set_xlabel('wavelength (nm)')
ax3.ticklabel_format(style='plain')
plt.tight_layout()
plt.show()
如您所见,这些曲线没有按正确方式进行缩放,以便它们在x轴方向上重叠并具有相同的尺寸。您能否帮我设置顶部x(波长)轴的正确参数?