Skip to content

Commit a36562b

Browse files
authored
Switch to probability density for marginals (#325)
1 parent 65e1f27 commit a36562b

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed
-141 KB
Loading

docs/_static/panda-to-star.gif

-13.7 KB
Loading

docs/quickstart.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ within your current working directory:
4949

5050
Morphing the panda :class:`.Dataset` into the star :class:`.Shape` with marginal plots.
5151

52-
If you don't want the marginal plots (the histograms on the sides), you can use classic mode:
52+
If you don't want the marginal plots (the probability density histograms on the sides),
53+
you can use classic mode:
5354

5455
.. code:: console
5556

src/data_morph/plotting/static.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import matplotlib.pyplot as plt
1010
import numpy as np
11-
from matplotlib.ticker import EngFormatter, MaxNLocator
11+
from matplotlib.ticker import EngFormatter
1212

1313
from ..data.stats import get_summary_statistics
1414
from .style import plot_with_custom_style
@@ -89,35 +89,24 @@ def plot(
8989
ax_histx = ax.inset_axes([0, 1.05, 1, 0.25], sharex=ax)
9090
ax_histy = ax.inset_axes([1.05, 0, 0.25, 1], sharey=ax)
9191

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+
)
121110

122111
res = get_summary_statistics(data, with_median=with_median)
123112

0 commit comments

Comments
 (0)