(self,
size: tuple,
rows: int,
cols: int,
spaces: Dict[Tuple[int, int], Box],
log_dims: Tuple[str, ...],
plt_params: Dict[str, Any])
| 33 | super().__init__('matplotlib', [plt.Figure, animation.Animation]) |
| 34 | |
| 35 | def create_figure(self, |
| 36 | size: tuple, |
| 37 | rows: int, |
| 38 | cols: int, |
| 39 | spaces: Dict[Tuple[int, int], Box], |
| 40 | log_dims: Tuple[str, ...], |
| 41 | plt_params: Dict[str, Any]) -> Tuple[Any, Dict[Tuple[int, int], Any]]: |
| 42 | size = (size[0] or 12, size[1] or 5) |
| 43 | figure, axes = plt.subplots(rows, cols, figsize=size) |
| 44 | self.current_figure = figure |
| 45 | axes = np.reshape(axes, (rows, cols)) |
| 46 | axes_by_pos = {} |
| 47 | subplot_aspect = (size[0] / cols) / (size[1] / rows) # x / y |
| 48 | for row in range(rows): |
| 49 | for col in range(cols): |
| 50 | axis = axes[row, col] |
| 51 | if (row, col) not in spaces: |
| 52 | axis.remove() |
| 53 | else: |
| 54 | bounds = spaces[(row, col)] |
| 55 | if bounds.spatial_rank == 2: |
| 56 | x, y = bounds.vector.item_names |
| 57 | axis.set_xlabel(display_name(x)) |
| 58 | axis.set_ylabel(display_name(y)) |
| 59 | # --- Log axes --- |
| 60 | x_log = bounds.vector.item_names[0] in log_dims |
| 61 | y_log = bounds.vector.item_names[1] in log_dims |
| 62 | if x_log: |
| 63 | axis.set_xscale('log') |
| 64 | if y_log: |
| 65 | axis.set_yscale('log') |
| 66 | # --- limits --- |
| 67 | x_range, y_range = [_get_range(bounds, i) for i in (0, 1)] |
| 68 | if None not in x_range: |
| 69 | if x_log and x_range[0] <= 0: |
| 70 | x_range = (1e-3 * x_range[1], x_range[1]) |
| 71 | axis.set_xlim(x_range) |
| 72 | if None not in y_range: |
| 73 | if y_log and y_range[0] <= 0: |
| 74 | y_range = (1e-3 * y_range[1], y_range[1]) |
| 75 | axis.set_ylim(y_range) |
| 76 | # --- Equal aspect --- |
| 77 | max_aspect = 4 if all([n in ['x', 'y', 'z'] for n in bounds.vector.item_names]) else 1.5 |
| 78 | if None not in x_range and None not in y_range and '_' not in bounds.vector.item_names: |
| 79 | x_size, y_size = x_range[1] - x_range[0], y_range[1] - y_range[0] |
| 80 | if not x_log and not y_log and x_size > 0 and y_size > 0 and max(x_size/y_size/subplot_aspect, y_size/x_size*subplot_aspect) < max_aspect: |
| 81 | axis.set_aspect('equal', adjustable='box') |
| 82 | # --- Remove labels if axes shared --- |
| 83 | for left_col in range(col): |
| 84 | if (row, left_col) in spaces and y in spaces[(row, left_col)].vector.item_names and spaces[(row, left_col)].vector[y] == bounds.vector[y] and math.is_finite(bounds.vector[y].lower).all: |
| 85 | axis.set_ylabel("") |
| 86 | axis.tick_params(labelleft=False) |
| 87 | axis.yaxis.set_minor_formatter(NullFormatter()) # sometimes required for log axis |
| 88 | for below_row in range(row + 1, rows + 1): |
| 89 | if (below_row, col) in spaces and x in spaces[(below_row, col)].vector.item_names and spaces[(below_row, col)].vector[x] == bounds.vector[x] and math.is_finite(bounds.vector[y].lower).all: |
| 90 | axis.set_xlabel("") |
| 91 | axis.tick_params(labelbottom=False) |
| 92 | axis.xaxis.set_minor_formatter(NullFormatter()) # sometimes required for log axis |
nothing calls this directly
no test coverage detected