92 plot_details_dict: dict) -> None:
93 """
94 Plot a histogram onto the PdfPages object.
95
96 Parameters:
97 data (np.ndarray): Array to plot a histogram of.
98 plot_details_dict (dict): Dictionary with keys such as 'title', 'xlabel', etc.
99
100 Returns:
101 Nothing. Mutates :self._pdf: with the new plot.
102 """
103 self._check_title_and_labels(plot_details_dict)
104
105 plt.figure(figsize=plot_details_dict.get('figsize', self._DEFAULT_FIG_SIZE))
106 ax = plt.gca()
107
108
109
110 if 'xticks' in plot_details_dict:
111 plt.xticks(**plot_details_dict['xticks'])
112
113 hist_style = plot_details_dict.get('hist_style', self._DEFAULT_HIST_STYLE)
114 bins = plot_details_dict.get('bins', self._DEFAULT_HIST_STYLE['bins'])
115
116 if plot_details_dict.get('linear', True) and plot_details_dict.get('log', True):
117 ax.hist(data, bins=bins, **plot_details_dict.get('linear_style', self._DEFAULT_HIST_STYLE['linear_style']))
118 ax.set_yscale('linear')
119
120 ax2 = ax.twinx()
121 ax2.hist(data, bins=bins, **plot_details_dict.get('log_style', self._DEFAULT_HIST_STYLE['log_style']))
122 ax2.set_yscale('log')
123
124
125 ax.set_zorder(2)
126 ax.patch.set_visible(False)
127 ax2.set_zorder(1)
128
129 linear_color = plot_details_dict.get('linear_style', self._DEFAULT_HIST_STYLE).get('color', self._DEFAULT_HIST_STYLE['linear_style']['color'])
130
131 ax.spines['left'].set_color(linear_color)
132 ax.yaxis.label.set_color(linear_color)
133 ax.tick_params('y', colors=linear_color)
134
135 log_color = plot_details_dict.get('log_style', self._DEFAULT_HIST_STYLE).get('color', self._DEFAULT_HIST_STYLE['log_style']['color'])
136 ax.spines['right'].set_color(log_color)
137 ax2.yaxis.label.set_color(log_color)
138 ax2.tick_params('y', which='both', colors=log_color)
139
140 handles, labels = ax.get_legend_handles_labels()
141 handles2, labels2 = ax2.get_legend_handles_labels()
142 handles = handles + handles2
143 labels = labels + labels2
144 plt.legend(handles=handles, labels=labels)
145 else:
146 hist_style = plot_details_dict.get('linear_style', self._DEFAULT_HIST_STYLE['linear_style'])
147 if plot_details_dict.get('log', self._DEFAULT_HIST_STYLE['log']):
148 hist_style = plot_details_dict.get('log_style', self._DEFAULT_HIST_STYLE['log_style'])
149 plt.hist(data, bins=bins, **hist_style)
150 if plot_details_dict.get('log', False):
151 plt.yscale('log')
152
153 plt.title(plot_details_dict['title'])
154 ax.set_xlabel(plot_details_dict['xlabel'])
155 if 'xlim' in plot_details_dict:
156 plt.xlim(plot_details_dict['xlim'])
157
158 if plot_details_dict.get('use_integer_xticks', False):
159 ax.xaxis.set_major_locator(MultipleLocator(base=1))
160
161 plt.tight_layout()
162 self._pdf.savefig()
163 plt.close()
164
165 return None
166