comparison generate_plot.py @ 0:89ae4a5724a5 draft

planemo upload for repository https://github.com/muon-spectroscopy-computational-project/muon-galaxy-tools/main/muspinsim_plot commit d130cf2c46d933fa9d0214ddbd5ddf860f322dc4
author muon-spectroscopy-computational-project
date Thu, 25 Aug 2022 16:17:15 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:89ae4a5724a5
1 import json
2 import sys
3
4 import matplotlib.pyplot as plt
5
6 import numpy as np
7
8
9 def main():
10 input_json_path = sys.argv[1]
11
12 plot_params = json.load(open(input_json_path, "r"))
13
14 for series in plot_params["mu_out_series"]:
15 mu_data = np.loadtxt(series['mu_data'], usecols=(0, 1))
16 x, y = mu_data.T
17 {
18 'line': lambda x, y, label, c, args:
19 plt.plot(x, y,
20 label=label,
21 c=c,
22 ls=args['linestyle'],
23 lw=args['linewidth']
24 ),
25 'points': lambda x, y, label, c, args:
26 plt.scatter(x, y,
27 label=label,
28 c=c,
29 s=args['pointscale'],
30 marker=args['pointstyle'],
31 )
32 }.get(series['series_type']['type'])(
33 x, y, series['mu_label'], series['colour'], series['series_type']
34 )
35
36 plt.xlabel(plot_params['xlab'])
37 plt.ylabel(plot_params['ylab'])
38 plt.title(plot_params['title'])
39 plt.legend(loc="upper right")
40
41 outfile = "outfile.{}".format(plot_params['out_file_type'])
42 plt.savefig(outfile, format=plot_params['out_file_type'])
43
44
45 if __name__ == '__main__':
46 main()