Coverage for examples/plot_isomorph_rdf.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1""" Plot data generated py isomorph.py 

2 

3""" 

4 

5import pickle 

6import os 

7 

8import matplotlib.pyplot as plt 

9import numpy as np 

10 

11# Load data from pickle file 

12with open('Data/isomorph.pkl', 'rb') as f: 

13 data = pickle.load(f) 

14 

15# Setup figure  

16fig, axs = plt.subplots(2, 1, figsize=(8, 6)) 

17fig.subplots_adjust(hspace=0.00) # Remove vertical space between axes 

18axs[0].set_ylabel('RDF') 

19axs[1].set_ylabel('RDF') 

20axs[0].set_xlabel('Distance') 

21axs[1].set_xlabel('Reduced distance') 

22axs[0].grid(linestyle='--', alpha=0.5) 

23axs[1].grid(linestyle='--', alpha=0.5) 

24 

25# Loop over simulation (i.e. elements in the list of data) 

26for simulation in data: 

27 # Unpack data for convenience 

28 rho = simulation['rho'] 

29 T = simulation['T'] 

30 distances = simulation['rdf']['distances'] 

31 rdf = np.mean(simulation['rdf']['rdf'], axis=0) 

32 

33 # Do the actual plotting in absolute and then reduced units 

34 axs[0].plot(distances, rdf, 

35 '-', label=f'rho={rho:.3f}, T={T:.3f}') 

36 axs[1].plot(distances * rho ** (1 / 3), rdf, 

37 '-', label=f'rho={rho:.3f}, T={T:.3f}') 

38 

39# Final touches and saving  

40axs[0].legend(loc='upper right') 

41axs[0].set_xlim([0.5, 3.5]) 

42axs[1].set_xlim([0.5, 3.5]) 

43fig.tight_layout() 

44fig.savefig('isomorph_rdf.pdf') 

45# plt.show() 

46