|
6 | 6 | from dataclasses import dataclass |
7 | 7 | from typing import Optional |
8 | 8 |
|
9 | | -import matplotlib.gridspec as gridspec |
10 | 9 | from matplotlib import pyplot as plt |
11 | 10 |
|
12 | 11 | from xrdpattern.parsing import MasterParser, Formats |
13 | 12 | from xrdpattern.xrd import XrayInfo, XrdData |
14 | 13 | from .pattern import XrdPattern |
15 | 14 | from .progress_tracker import TrackedCollection |
16 | | -from .visualization import multiplot, define_angle_start_stop_ax, define_recorded_angles_ax, define_spg_ax |
17 | 15 |
|
18 | 16 | patterdb_logger = logging.getLogger(__name__) |
19 | 17 | patterdb_logger.setLevel(logging.INFO) |
@@ -165,38 +163,17 @@ def show_gallery(self): |
165 | 163 | if user_input.lower() == 'q': |
166 | 164 | break |
167 | 165 |
|
168 | | - def show_histograms(self, save_fpath : Optional[str] = None, attach_colorbar : bool = True): |
169 | | - fig = plt.figure(figsize=(12, 8)) |
170 | | - |
171 | | - figure = gridspec.GridSpec(nrows=2, ncols=1, figure=fig, hspace=0.35) |
172 | | - figure.update(top=0.96, bottom=0.075) |
173 | | - upper_half = figure[0].subgridspec(1, 3) |
174 | | - ax2 = fig.add_subplot(upper_half[:, :]) |
175 | | - define_spg_ax(patterns=self.patterns, ax=ax2) |
176 | | - |
177 | | - lower_half = figure[1].subgridspec(1, 2) |
178 | | - ax3 = fig.add_subplot(lower_half[:, 0]) |
179 | | - define_recorded_angles_ax(patterns=self.patterns, ax=ax3) |
180 | | - |
181 | | - if attach_colorbar: |
182 | | - lower_half_right = lower_half[1].subgridspec(nrows=3, ncols=3, width_ratios=[3, 3, 4] , hspace=0, wspace=0) |
183 | | - ax4 = fig.add_subplot(lower_half_right[1:, :2]) # scaatter |
184 | | - ax5 = fig.add_subplot(lower_half_right[:1, :2], sharex=ax4) # Above |
185 | | - ax6 = fig.add_subplot(lower_half_right[1:, 2:], sharey=ax4) # Right |
186 | | - ax7 = fig.add_subplot(lower_half_right[:1, 2:]) |
187 | | - ax7.axis('off') |
188 | | - else: |
189 | | - lower_half_right = lower_half[1].subgridspec(nrows=3, ncols=4, width_ratios=[2.75, 3, 3, 3], hspace=0, wspace=0) |
190 | | - ax4 = fig.add_subplot(lower_half_right[1:, 1:3]) # scatter |
191 | | - ax5 = fig.add_subplot(lower_half_right[:1, 1:3], sharex=ax4) # Above |
192 | | - ax6 = fig.add_subplot(lower_half_right[1:, 3:4], sharey=ax4) # Right |
193 | | - ax7 = fig.add_subplot(lower_half_right[:4, :1]) |
194 | | - |
195 | | - define_angle_start_stop_ax(patterns=self.patterns, density_ax=ax4, top_marginal=ax5, right_marginal=ax6, cmap_ax=ax7, attach_colorbar=attach_colorbar) |
196 | | - |
197 | | - if save_fpath: |
198 | | - plt.savefig(save_fpath) |
199 | | - plt.show() |
200 | | - |
201 | | - |
202 | 166 |
|
| 167 | +def multiplot(patterns : list[XrdPattern], start_idx : int): |
| 168 | + labels = [p.get_name() for p in patterns] |
| 169 | + fig, axes = plt.subplots(4, 8, figsize=(20, 10)) |
| 170 | + for i, pattern in enumerate(patterns): |
| 171 | + ax = axes[i // 8, i % 8] |
| 172 | + x_values, intensities = pattern.get_pattern_data(apply_standardization=False) |
| 173 | + ax.set_xlabel(r'$2\theta$ (Degrees)') |
| 174 | + ax.plot(x_values, intensities, label='Interpolated Intensity') |
| 175 | + ax.set_ylabel('Intensity') |
| 176 | + ax.set_title(f'({i+start_idx}){labels[i][:20]}') |
| 177 | + ax.legend(fontsize=8) |
| 178 | + plt.tight_layout() |
| 179 | + plt.show() |
0 commit comments