|
8 | 8 |
|
9 | 9 | import matplotlib.pyplot as plt |
10 | 10 | import numpy as np |
11 | | -from matplotlib.ticker import EngFormatter, MaxNLocator |
| 11 | +from matplotlib.ticker import EngFormatter |
12 | 12 |
|
13 | 13 | from ..data.stats import get_summary_statistics |
14 | 14 | from .style import plot_with_custom_style |
@@ -89,35 +89,24 @@ def plot( |
89 | 89 | ax_histx = ax.inset_axes([0, 1.05, 1, 0.25], sharex=ax) |
90 | 90 | ax_histy = ax.inset_axes([1.05, 0, 0.25, 1], sharey=ax) |
91 | 91 |
|
92 | | - ax_histy.xaxis.set_major_formatter(tick_formatter) |
93 | | - ax_histx.yaxis.set_major_formatter(tick_formatter) |
94 | | - |
95 | | - (x_marginal_counts, x_marginal_bins), (y_marginal_counts, y_marginal_bins) = ( |
96 | | - marginals |
97 | | - ) |
98 | | - |
99 | | - ax_histx.set(xlim=x_bounds, ylim=(0, np.ceil(x_marginal_counts.max() * 2))) |
100 | | - ax_histy.set(xlim=(0, np.ceil(y_marginal_counts.max() * 2)), ylim=y_bounds) |
101 | | - |
102 | | - # no labels on marginal axis that shares with scatter plot |
103 | | - ax_histx.tick_params(axis='x', labelbottom=False) |
104 | | - ax_histy.tick_params(axis='y', labelleft=False) |
105 | | - |
106 | | - # move marginal axis ticks that are visible to the corner and only show the non-zero label |
107 | | - locator = MaxNLocator(2, integer=True, prune='lower') |
108 | | - ax_histx.tick_params(axis='y', labelleft=False, labelright=True) |
109 | | - ax_histx.yaxis.set_major_locator(locator) |
110 | | - ax_histy.tick_params(axis='x', labelbottom=False, labeltop=True) |
111 | | - ax_histy.xaxis.set_major_locator(locator) |
112 | | - |
113 | | - ax_histx.hist(data.x, bins=x_marginal_bins, color='slategray', ec='black') |
114 | | - ax_histy.hist( |
115 | | - data.y, |
116 | | - bins=y_marginal_bins, |
117 | | - orientation='horizontal', |
118 | | - color='slategray', |
119 | | - ec='black', |
120 | | - ) |
| 92 | + for marginal_ax, values, (_, bins), orientation in zip( |
| 93 | + [ax_histx, ax_histy], |
| 94 | + [data.x, data.y], |
| 95 | + marginals, |
| 96 | + ['vertical', 'horizontal'], |
| 97 | + strict=True, |
| 98 | + ): |
| 99 | + marginal_ax.xaxis.set_visible(False) |
| 100 | + marginal_ax.yaxis.set_visible(False) |
| 101 | + marginal_ax.hist( |
| 102 | + values, |
| 103 | + bins=bins, |
| 104 | + density=True, |
| 105 | + color='black', |
| 106 | + alpha=0.7, |
| 107 | + ec='#EAEAF2', |
| 108 | + orientation=orientation, |
| 109 | + ) |
121 | 110 |
|
122 | 111 | res = get_summary_statistics(data, with_median=with_median) |
123 | 112 |
|
|
0 commit comments