Coverage for tcvx21/plotting/plot_comparison_1d_m.py: 94%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Plotting routines for 1D observables
3"""
4import matplotlib.pyplot as plt
5import tcvx21
6plt.style.use(tcvx21.style_sheet)
8from tcvx21.quant_validation.ricci_metric_m import calculate_normalised_ricci_distance_from_observables
9from tcvx21.plotting.labels_m import add_twinx_label, add_x_zero_line, add_y_zero_line, make_labels, format_yaxis
11from tcvx21.quant_validation.latex_table_writer_m import observable_latex
14def plot_1D_comparison(field_direction, diagnostic, observable,
15 experimental_data, simulation_data, **kwargs):
16 """
17 Plots a 1D (line data) observable, with different values represented via a constant color
18 """
19 fig, ax = plt.subplots()
21 add_x_zero_line(ax)
22 add_y_zero_line(ax)
24 if 'kurtosis' in observable:
25 add_y_zero_line(ax, level=3.0)
27 reference = experimental_data[field_direction].get_observable(diagnostic, observable)
28 reference_available = not(reference.is_empty)
29 if reference_available:
30 reference.plot(ax, **kwargs)
31 else:
32 # Use one of the simulations as the "reference" to access the properties
33 reference = list(simulation_data.values())[0][field_direction]\
34 .get_observable(diagnostic, observable)
36 field_direction_string, diagnostic_string, observable_string = \
37 make_labels(field_direction, diagnostic, reference)
39 add_twinx_label(ax, field_direction_string)
41 ax.set_title(f"{diagnostic_string}: {observable_string}")
43 for case in simulation_data.values():
45 simulation = case[field_direction].get_observable(diagnostic, observable)
46 if simulation.is_empty:
47 continue
49 line = simulation.plot(ax, trim_to_x=reference.xlim, **kwargs)
50 if reference_available:
51 d = calculate_normalised_ricci_distance_from_observables(simulation=simulation, experiment=reference)
52 line.set_label(f"{line.get_label()}: d={d:3.2f}")
53 else:
54 line.set_label(f"{line.get_label()}")
56 # Set the ylim to show all data
57 ax.set_ylim(*reference.ylims_in_trim(
58 [case[field_direction].get_observable(diagnostic, observable) for case in simulation_data.values() if not case[field_direction].is_empty],
59 trim_to_x=reference.xlim))
61 # Apply custom limits if they are defined
62 reference.apply_plot_limits(ax)
63 plt.draw()
64 format_yaxis(ax)
66 plt.legend()
68 return fig, ax