1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
import numpy as np
import matplotlib.pyplot as plt
e = 1.602177E-19
C = 2.99792458E8
h = 6.6260693E-34
dstep = 0.05 # incrément sur l'axe du haut
def ax1_2_ax2(x):
"""
Conversion from x1 to x2 scale
"""
return h*C/(x*e)*1E9
def ax2_2_ax1(x):
"""
Conversion from x2 to x1 scale
"""
return h*C/(x*e)*1E9
def update_ax2(ax1):
y1_1, y2_1 = ax1.get_xlim()
ax2.set_xlim(y1_1,y2_1)
y1_2=ax1_2_ax2(y1_1)
y2_2=ax1_2_ax2(y2_1)
dy=(y2_2-y1_2)
Xticlabel=np.arange(np.around(y1_2/dstep)*dstep ,
np.around(y2_2/dstep)*dstep , np.sign(dy)*dstep)
Xtic=ax2_2_ax1(Xticlabel)
ax2.set_xticks(Xtic)
ax2.set_xticklabels(Xticlabel)
ax2.figure.canvas.draw()
fig=plt.figure('Spectrum',figsize=(15, 8))
ax1=fig.add_subplot(111)
ax2=ax1.twiny()
ax1.callbacks.connect("xlim_changed", update_ax2)
ax1.set_xlim(X.min(),X.max())
ax1.plot(X,Y,'r-',label='Spectrum',linewidth=3) |
Partager