#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
    Tracés de quantités de matière lors de l'avancement d'une réaction chimique
"""

import numpy as np  # module mathématique
import matplotlib.pyplot as plt  # module graphique

"""
    Données
"""
# Coefficients stoechiometriques I2 + S2O3 -> S4O6 + I
c = np.array([1, 1, 1, 1])

# Quantités de matière initiales [nI2, nS2O3, nS4O6, nI]
n0 = np.array([1, 1, 0, 0])

"""
    Modélisation
"""
# Plage d'avancement : 100 pts de 0 à 1
x = np.linspace(0, 1, 100)

# Calcul des quantités de matière
nA = n0[0] - c[0]*x
nB = n0[1] - c[1]*x
nC = n0[2] + c[2]*x
nD = n0[3] + c[3]*x

"""
    Graphique
"""
plt.figure()  # création de la figure

# tracé du nuage de points
plt.plot(x, nA, 'k-', label='I2')
plt.plot(x, nB, 'b-', label='S2O3')
plt.plot(x, nC, 'r-', label='S4O6')
plt.plot(x, nD, 'g-', label='I')

plt.title('Tableau d\'avancement')  # titre du graphique
plt.xlabel('avancement x (mol)')  # titre des abscisses
plt.ylabel('quantités de matière n (mol)')  # titre des ordonnées
plt.minorticks_on()
plt.grid(which='both', color='black', linestyle='-', linewidth='0.1')  # affichage d'une grille
plt.legend()  # affichage de la légende
plt.show()  # affichage du graphique
