Skip to content

Commit b42a204

Browse files
authored
refactor(api)!: cleanup, remove redundant, updated label positioning (#589)
* docs: update CITATION.cff * feat(BREAKING): renames * feat(BREAKING): removing extras * feat(BREAKING): use seaborn in examples feat(BREAKING): use seaborn in examples fix: adjust cmap * fix: update label positioning * fix: update existing tests * feat: add new add_text tests
1 parent 6cff4a0 commit b42a204

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+555
-511
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Note: This ignores the notebook tests (which are run via
4141
sure to run the complete suite before submitting a PR
4242

4343
```bash
44-
pytest --mpl
44+
python -m pytest -r sa --mpl --mpl-results-path=pytest_results -n 4
4545
```
4646

4747
### Making a pull request
@@ -56,7 +56,7 @@ If you modified expected outcomes of the tests. New baseline visuals can be
5656
generated using this command:
5757

5858
```bash
59-
pytest --mpl-generate-path=tests/baseline
59+
python -m pytest -r sa --mpl -n 4 --mpl-generate-path=tests/baseline
6060
```
6161

6262
Only include the actually modified baseline images in your PR! Running `git add

examples/1d_histograms/1d_comparison_difference.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838
comparison="difference", # <--
3939
)
4040

41-
add_text("Comparison of two hist with difference plot", ax=ax_main)
42-
add_text("Difference ax", x="right", ax=ax_comparison)
41+
add_text(
42+
"Comparison of two hist with difference plot",
43+
ax=ax_main,
44+
fontsize="small",
45+
loc="over left",
46+
)
47+
add_text("Difference ax", ax=ax_comparison, loc="over right", fontsize="small")
4348

4449
fig.savefig("1d_comparison_difference.svg", bbox_inches="tight")

examples/model_ex/model_all_comparisons.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
df = get_dummy_data()
1111

12-
from mplhep import get_color_palette
12+
import seaborn as sns
1313

1414
# Define the histograms
1515

@@ -23,7 +23,7 @@
2323

2424
background_categories = [0, 1, 2]
2525
background_categories_labels = [f"c{i}" for i in background_categories]
26-
background_categories_colors = get_color_palette(
26+
background_categories_colors = sns.color_palette(
2727
"cubehelix", len(background_categories)
2828
)
2929

@@ -52,20 +52,24 @@
5252
background_hists = [background_scaling_factor * h for h in background_hists]
5353

5454
###
55+
import matplotlib.pyplot as plt
56+
5557
from mplhep import (
5658
add_text,
57-
create_comparison_figure,
5859
plot_comparison,
5960
plot_data_model_comparison,
6061
set_fitting_ylabel_fontsize,
6162
)
6263

63-
fig, axes = create_comparison_figure(
64-
figsize=(6, 13),
64+
fig, axes = plt.subplots(
6565
nrows=6,
66+
figsize=(6, 13),
6667
gridspec_kw={"height_ratios": [3, 1, 1, 1, 1, 1]},
67-
hspace=0.3,
6868
)
69+
fig.subplots_adjust(hspace=0.3)
70+
for ax in axes[:-1]:
71+
ax.xaxis.set_ticklabels([])
72+
ax.set_xlabel(" ")
6973
background_sum = sum(background_hists)
7074

7175
plot_data_model_comparison(
@@ -84,8 +88,12 @@
8488
add_text(
8589
r"Multiple data-model comparisons, $\mathbf{with}$ model uncertainty",
8690
ax=axes[0],
91+
loc="over left",
92+
fontsize="small",
93+
)
94+
add_text(
95+
r' $\mathbf{→}$ comparison = "ratio"', ax=axes[1], loc="over left", fontsize=13
8796
)
88-
add_text(r' $\mathbf{→}$ comparison = "ratio"', ax=axes[1], fontsize=13)
8997

9098
for k_comp, comparison in enumerate(
9199
["split_ratio", "pull", "relative_difference", "difference"], start=2
@@ -106,6 +114,7 @@
106114
rf' $\mathbf{{→}}$ comparison = "{comparison}"',
107115
ax=ax_comparison,
108116
fontsize=13,
117+
loc="over left",
109118
)
110119
set_fitting_ylabel_fontsize(ax_comparison)
111120

examples/model_ex/model_all_comparisons_no_model_unc.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
df = get_dummy_data()
1111

12-
from mplhep import get_color_palette
12+
import seaborn as sns
1313

1414
# Define the histograms
1515

@@ -23,7 +23,7 @@
2323

2424
background_categories = [0, 1, 2]
2525
background_categories_labels = [f"c{i}" for i in background_categories]
26-
background_categories_colors = get_color_palette(
26+
background_categories_colors = sns.color_palette(
2727
"cubehelix", len(background_categories)
2828
)
2929

@@ -52,22 +52,25 @@
5252
background_hists = [background_scaling_factor * h for h in background_hists]
5353

5454
###
55+
import matplotlib.pyplot as plt
5556
import numpy as np
5657

5758
from mplhep import (
5859
add_text,
59-
create_comparison_figure,
6060
plot_comparison,
6161
plot_data_model_comparison,
6262
set_fitting_ylabel_fontsize,
6363
)
6464

65-
fig, axes = create_comparison_figure(
66-
figsize=(6, 13),
65+
fig, axes = plt.subplots(
6766
nrows=6,
67+
figsize=(6, 13),
6868
gridspec_kw={"height_ratios": [3, 1, 1, 1, 1, 1]},
69-
hspace=0.3,
7069
)
70+
fig.subplots_adjust(hspace=0.3)
71+
for ax in axes[:-1]:
72+
ax.xaxis.set_ticklabels([])
73+
ax.set_xlabel(" ")
7174
background_sum = sum(background_hists)
7275

7376
plot_data_model_comparison(
@@ -87,8 +90,12 @@
8790
add_text(
8891
r"Multiple data-model comparisons, $\mathbf{without}$ model uncertainty",
8992
ax=axes[0],
93+
loc="over left",
94+
fontsize="small",
95+
)
96+
add_text(
97+
r' $\mathbf{→}$ comparison = "ratio"', ax=axes[1], loc="over left", fontsize=13
9098
)
91-
add_text(r' $\mathbf{→}$ comparison = "ratio"', ax=axes[1], fontsize=13)
9299

93100
for k_comp, comparison in enumerate(
94101
["split_ratio", "pull", "relative_difference", "difference"], start=2
@@ -117,6 +124,7 @@
117124
add_text(
118125
rf' $\mathbf{{→}}$ comparison = "{comparison}"',
119126
ax=ax_comparison,
127+
loc="over left",
120128
fontsize=13,
121129
)
122130
set_fitting_ylabel_fontsize(ax_comparison)

examples/model_ex/model_examples_pull.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
df = get_dummy_data()
1111

12-
from mplhep import get_color_palette
12+
import seaborn as sns
1313

1414
# Define the histograms
1515

@@ -23,7 +23,7 @@
2323

2424
background_categories = [0, 1, 2]
2525
background_categories_labels = [f"c{i}" for i in background_categories]
26-
background_categories_colors = get_color_palette(
26+
background_categories_colors = sns.color_palette(
2727
"cubehelix", len(background_categories)
2828
)
2929

examples/model_ex/model_examples_pull_no_model_unc.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
df = get_dummy_data()
1111

12-
from mplhep import get_color_palette
12+
import seaborn as sns
1313

1414
# Define the histograms
1515

@@ -23,7 +23,7 @@
2323

2424
background_categories = [0, 1, 2]
2525
background_categories_labels = [f"c{i}" for i in background_categories]
26-
background_categories_colors = get_color_palette(
26+
background_categories_colors = sns.color_palette(
2727
"cubehelix", len(background_categories)
2828
)
2929

@@ -52,7 +52,7 @@
5252
background_hists = [background_scaling_factor * h for h in background_hists]
5353

5454
###
55-
from mplhep import add_luminosity, plot_data_model_comparison
55+
from mplhep import plot_data_model_comparison
5656

5757
fig, ax_main, ax_comparison = plot_data_model_comparison(
5858
data_hist=data_hist,
@@ -65,6 +65,4 @@
6565
model_uncertainty=False, # <--
6666
)
6767

68-
add_luminosity(collaboration="mplhep", ax=ax_main, is_data=False)
69-
7068
fig.savefig("model_examples_pull_no_model_unc.svg", bbox_inches="tight")

examples/model_ex/model_examples_stacked.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
df = get_dummy_data()
1111

12-
from mplhep import get_color_palette
12+
import seaborn as sns
1313

1414
# Define the histograms
1515

@@ -23,7 +23,7 @@
2323

2424
background_categories = [0, 1, 2]
2525
background_categories_labels = [f"c{i}" for i in background_categories]
26-
background_categories_colors = get_color_palette(
26+
background_categories_colors = sns.color_palette(
2727
"cubehelix", len(background_categories)
2828
)
2929

@@ -55,7 +55,7 @@
5555
signal_hist *= signal_scaling_factor
5656

5757
###
58-
from mplhep import add_luminosity, histplot, plot_data_model_comparison
58+
from mplhep import histplot, plot_data_model_comparison
5959

6060
fig, ax_main, ax_comparison = plot_data_model_comparison(
6161
data_hist=data_hist,
@@ -77,8 +77,4 @@
7777

7878
ax_main.legend()
7979

80-
add_luminosity(
81-
collaboration="mplhep", ax=ax_main, lumi=3, lumi_unit="zb", preliminary=True
82-
)
83-
8480
fig.savefig("model_examples_stacked.svg", bbox_inches="tight")

examples/model_ex/model_examples_stacked_unstacked.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
df = get_dummy_data()
1111

12-
from mplhep import get_color_palette
12+
import seaborn as sns
1313

1414
# Define the histograms
1515

@@ -23,7 +23,7 @@
2323

2424
background_categories = [0, 1, 2]
2525
background_categories_labels = [f"c{i}" for i in background_categories]
26-
background_categories_colors = get_color_palette(
26+
background_categories_colors = sns.color_palette(
2727
"cubehelix", len(background_categories)
2828
)
2929

examples/model_ex/model_examples_unstacked.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
df = get_dummy_data()
1111

12-
from mplhep import get_color_palette
12+
import seaborn as sns
1313

1414
# Define the histograms
1515

@@ -23,7 +23,7 @@
2323

2424
background_categories = [0, 1, 2]
2525
background_categories_labels = [f"c{i}" for i in background_categories]
26-
background_categories_colors = get_color_palette(
26+
background_categories_colors = sns.color_palette(
2727
"cubehelix", len(background_categories)
2828
)
2929

examples/model_ex/model_with_stacked_and_unstacked_function_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def f_background2(x):
4343
function_range=range,
4444
)
4545

46-
add_text("Model made of functions", ax=ax)
46+
add_text("Model made of functions", ax=ax, loc="over left", fontsize="small")
4747

4848
fig.savefig(
4949
"model_with_stacked_and_unstacked_function_components.svg", bbox_inches="tight"

0 commit comments

Comments
 (0)