-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
34 lines (29 loc) · 916 Bytes
/
plot.py
File metadata and controls
34 lines (29 loc) · 916 Bytes
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
from pathlib import Path
import typer
from matplotlib import pyplot as plt
from h5py import File
app = typer.Typer()
@app.command()
def main(items: list[str]):
prim = "comoving_mass_density"
filenames = []
for item in items:
if item.endswith('.h5'):
filenames.append(Path(item))
else:
prim = item
fig, ax1 = plt.subplots()
for filename in filenames:
with File(filename, 'r') as h5f:
xi, xo = h5f["__config__"]["domain"][...]
x = h5f["cell_coordinate"][...]
if prim in h5f:
y = h5f[prim][...]
ax1.plot(x, y, label=filename.name, color='k')
ax1.set_xlim(xi, xo)
ax1.set_ylim(0.0)
plt.show()
else:
print(f"Primitive quantity '{prim}' not found in file {filename}.")
if __name__ == "__main__":
app()