import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import Slider


tmax = 50
EA = 80000
R = 8.31
k0 = 10

kB = 1.38e-23
g = 9.81
zmax = 50000
p0 = 10000
M = 28.8e-3
Na = 6.022e23
m = M/Na

# Taille du texte :
s = 15

def tracer(event) :

    z = np.linspace(0, zmax, 1000)
    H = kB*sT.val/(m*g)
    p = np.exp(-z/H)
    line1.set_data(z, p)
    reticule.set_data([0, H, H], [np.exp(-1), np.exp(-1), 0])
    ax.set_xlim(0, zmax)
    ax.set_ylim(0, 1)
    ax.texts = []
    ax.text(H, 0.1, r'$H = ' + str(round(H, 2 - int(np.log(H) / np.log(10)))) + '\;(m)$', color = (.3, .3, .3), size = s)
    plt.draw()

fig = plt.figure()
ax = fig.add_subplot(111)
position = list(ax.get_position().bounds)

position[2] -= .1
position[1] +=0.05
ax.set_position(position)

ax.tick_params(axis = 'both', labelsize = s, pad = 5)
ax.set_title(r'Atmosphère isotherme', size = s, pad = 3)
ax.set_xlabel('Altitude (m)', size = s)
ax.set_ylabel('Pression (bar)', size = s)
line1, = ax.plot([], [], linewidth = 3)
reticule, = ax.plot([], [], ':', linewidth = 2, color = (.3, .3, .3))

ax_T = fig.add_axes([.9, .3, .02, .5])
sT = Slider(ax_T,  r'$T \;(K)$', 273 , 323, valinit = 300, valfmt = '%i', orientation = 'vertical', facecolor = 'red')
sT.on_changed(tracer)
sT.label.set_size(s)
sT.valtext.set_size(s)

tracer(1)
mng = plt.get_current_fig_manager()

plt.show()
