-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
78 lines (63 loc) · 2.63 KB
/
Copy pathplot.py
File metadata and controls
78 lines (63 loc) · 2.63 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import matplotlib.pyplot as plt
import numpy as np
import glob
# Inizializzazione del dizionario
species = {}
# Apertura del file in modalità lettura
with open('species', 'r') as file:
# Lettura di ogni riga del file
for i, line in enumerate(file):
# Rimozione degli spazi bianchi iniziali e finali
line = line.strip()
# Estrazione del nome della specie chimica
name = line.split()[0]
# Aggiunta della specie al dizionario con il suo numero di riga come valore
species[name.lower()] = i + 1
dat_files = glob.glob('*.dat')
# Print the list of .dat files
print("Risultati disponibili:\n")
for i, filename in enumerate(dat_files, 1):
print(f"{i}. {filename}")
# Ask the user to select a file
file_index = int(input("\nInserisci l'indice del file da analizzare: ")) - 1
selected_file = dat_files[file_index]
# Load data
data = np.loadtxt(selected_file)
# Find species with values greater than 1e-14 and their max values
species_to_plot = [(name, np.max(data[:, column-1])) for name, column in species.items() if column-1 < data.shape[1] and np.any(data[:, column-1] > 1e-14)]
# Print report
print("\nSpecie chimiche che hanno superato un mix ratio di 10^-14:\n")
for i, name in enumerate(species_to_plot, 1):
print(f"{i}. {name}")
# Ask user for input
plot_all = input("\nVuoi mostrarle tutte? (s/n) ")
if plot_all.lower() != 's':
indices_to_plot = input("Seleziona le specie. Singolarmente separate da ',' o con '-' per un intervallo: ")
indices_to_plot = indices_to_plot.split(',')
expanded_indices = []
for index in indices_to_plot:
if '-' in index:
start, end = map(int, index.split('-'))
expanded_indices.extend(range(start, end + 1))
else:
expanded_indices.append(int(index))
indices_to_plot = [index - 1 for index in expanded_indices]
species_to_plot = [species_to_plot[index] for index in indices_to_plot]
# Creazione del grafico
plt.figure(figsize=(10, 10)) # dimensioni del grafico
plt.rcParams['axes.facecolor'] = 'white' # colore di sfondo degli assi
plt.grid(color='gray', linestyle='--', linewidth=0.5) # griglia
plt.yscale('log')
plt.xscale('log')
plt.xlim([1e-14, 1])
plt.ylim([1, 1e-10])
plt.xlabel('Mixing ratio')
plt.ylabel('Pressure (bar)')
plt.title(selected_file)
for name, _ in species_to_plot:
plt.plot(data[:, species[name]-1], data[:, 1], label=name)
# Mostra la legenda e salva il grafico in un file PDF
plt.legend()
# Salva il grafico in formato PNG invece di PDF
plt.savefig("plot.png", dpi=300, bbox_inches='tight')
plt.show()