plothist 1.3.2__py3-none-any.whl → 1.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plothist/__init__.py +66 -74
- plothist/_version.py +21 -0
- plothist/_version.pyi +2 -0
- plothist/comparison.py +115 -106
- plothist/examples/1d_hist/1d_comparison_asymmetry.py +37 -0
- plothist/examples/1d_hist/1d_comparison_difference.py +40 -0
- plothist/examples/1d_hist/1d_comparison_efficiency.py +37 -0
- plothist/examples/1d_hist/1d_comparison_only_efficiency.py +33 -0
- plothist/examples/1d_hist/1d_comparison_pull.py +37 -0
- plothist/examples/1d_hist/1d_comparison_ratio.py +37 -0
- plothist/examples/1d_hist/1d_comparison_relative_difference.py +37 -0
- plothist/examples/1d_hist/1d_comparison_split_ratio.py +37 -0
- plothist/examples/1d_hist/1d_elt1.py +38 -0
- plothist/examples/1d_hist/1d_elt1_stacked.py +45 -0
- plothist/examples/1d_hist/1d_elt2.py +33 -0
- plothist/examples/1d_hist/1d_hist_simple.py +28 -0
- plothist/examples/1d_hist/1d_int_category.py +41 -0
- plothist/examples/1d_hist/1d_profile.py +33 -0
- plothist/examples/1d_hist/1d_side_by_side.py +58 -0
- plothist/examples/1d_hist/1d_str_category.py +41 -0
- plothist/examples/1d_hist/README.rst +4 -0
- plothist/examples/2d_hist/2d_hist_correlations.py +65 -0
- plothist/examples/2d_hist/2d_hist_simple.py +28 -0
- plothist/examples/2d_hist/2d_hist_simple_discrete_colormap.py +42 -0
- plothist/examples/2d_hist/2d_hist_uneven.py +28 -0
- plothist/examples/2d_hist/2d_hist_with_projections.py +36 -0
- plothist/examples/2d_hist/README.rst +4 -0
- plothist/examples/README.rst +7 -0
- plothist/examples/advanced/1d_comparison_advanced.py +87 -0
- plothist/examples/advanced/1d_side_by_side_with_numbers.py +81 -0
- plothist/examples/advanced/README.rst +4 -0
- plothist/examples/advanced/asymmetry_comparison_advanced.py +133 -0
- plothist/examples/advanced/model_examples_flatten2D.py +86 -0
- plothist/examples/func_1d/README.rst +4 -0
- plothist/examples/func_1d/fct_1d.py +27 -0
- plothist/examples/func_1d/fct_1d_stacked.py +42 -0
- plothist/examples/model_ex/README.rst +4 -0
- plothist/examples/model_ex/model_all_comparisons.py +103 -0
- plothist/examples/model_ex/model_all_comparisons_no_model_unc.py +115 -0
- plothist/examples/model_ex/model_examples_pull.py +56 -0
- plothist/examples/model_ex/model_examples_pull_no_model_unc.py +59 -0
- plothist/examples/model_ex/model_examples_stacked.py +74 -0
- plothist/examples/model_ex/model_examples_stacked_unstacked.py +60 -0
- plothist/examples/model_ex/model_examples_unstacked.py +57 -0
- plothist/examples/model_ex/model_with_stacked_and_unstacked_function_components.py +50 -0
- plothist/examples/model_ex/model_with_stacked_and_unstacked_histograms_components.py +69 -0
- plothist/examples/model_ex/ratio_data_vs_model_with_stacked_and_unstacked_function_components.py +61 -0
- plothist/examples/utility/README.rst +4 -0
- plothist/examples/utility/add_text_example.py +39 -0
- plothist/examples/utility/color_palette_hists.py +94 -0
- plothist/examples/utility/color_palette_squares.py +100 -0
- plothist/examples/utility/matplotlib_vs_plothist_style.py +63 -0
- plothist/histogramming.py +77 -48
- plothist/plothist_style.py +61 -62
- plothist/plotters.py +280 -233
- plothist/test_helpers.py +43 -0
- plothist/variable_registry.py +62 -43
- {plothist-1.3.2.dist-info → plothist-1.5.0.dist-info}/METADATA +20 -12
- plothist-1.5.0.dist-info/RECORD +63 -0
- {plothist-1.3.2.dist-info → plothist-1.5.0.dist-info}/licenses/LICENSE +1 -1
- plothist/dummy_data.csv +0 -100001
- plothist/get_dummy_data.py +0 -17
- plothist/scripts/__init__.py +0 -2
- plothist/scripts/install_latin_modern_fonts.py +0 -145
- plothist/scripts/make_examples.py +0 -210
- plothist-1.3.2.dist-info/RECORD +0 -18
- plothist-1.3.2.dist-info/entry_points.txt +0 -3
- {plothist-1.3.2.dist-info → plothist-1.5.0.dist-info}/WHEEL +0 -0
- {plothist-1.3.2.dist-info → plothist-1.5.0.dist-info}/licenses/AUTHORS.md +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Difference
|
|
3
|
+
==========
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the difference [h1-h2].
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import add_text, plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathcal{H}_{1}$",
|
|
33
|
+
h2_label=r"$\mathcal{H}_{2}$",
|
|
34
|
+
comparison="difference", # <--
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
add_text("Comparison of two hist with difference plot", ax=ax_main)
|
|
38
|
+
add_text("Difference ax", x="right", ax=ax_comparison)
|
|
39
|
+
|
|
40
|
+
fig.savefig("1d_comparison_difference.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Efficiency
|
|
3
|
+
==========
|
|
4
|
+
|
|
5
|
+
Compare the ratio between two histograms h1 and h2 when the entries of h1 are a subset of the entries of h2.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x_total = df[name][df["category"] == 2]
|
|
15
|
+
x_sample = x_total[: int(len(x_total) * 0.75)]
|
|
16
|
+
|
|
17
|
+
x_range = (min(x_total), max(x_total))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h_sample = make_hist(x_sample, bins=50, range=x_range)
|
|
22
|
+
h_total = make_hist(x_total, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h_sample,
|
|
29
|
+
h_total,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathit{H}_{Sample}$",
|
|
33
|
+
h2_label=r"$\mathit{H}_{Total}$",
|
|
34
|
+
comparison="efficiency", # <--
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_efficiency.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Comparison
|
|
3
|
+
==========
|
|
4
|
+
|
|
5
|
+
Plot the comparison between two 1D histograms.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x_total = df[name][df["category"] == 2]
|
|
15
|
+
x_sample = x_total[: int(len(x_total) * 0.75)]
|
|
16
|
+
|
|
17
|
+
x_range = (min(x_total), max(x_total))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h_sample = make_hist(x_sample, bins=50, range=x_range)
|
|
22
|
+
h_total = make_hist(x_total, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
import matplotlib.pyplot as plt
|
|
26
|
+
|
|
27
|
+
from plothist import plot_comparison
|
|
28
|
+
|
|
29
|
+
fig, ax = plt.subplots()
|
|
30
|
+
|
|
31
|
+
plot_comparison(h_sample, h_total, ax=ax, xlabel=name, comparison="efficiency")
|
|
32
|
+
|
|
33
|
+
fig.savefig("1d_comparison_only_efficiency.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pull
|
|
3
|
+
====
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the pull method.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$h_1$",
|
|
33
|
+
h2_label=r"$h_2$",
|
|
34
|
+
comparison="pull", # <---
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_pull.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Ratio
|
|
3
|
+
=====
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the ratio [h1/h2].
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
# Default comparison is ratio
|
|
28
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
29
|
+
h1,
|
|
30
|
+
h2,
|
|
31
|
+
xlabel=name,
|
|
32
|
+
ylabel="Entries",
|
|
33
|
+
h1_label="h1",
|
|
34
|
+
h2_label="h2",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_ratio.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Relative difference
|
|
3
|
+
===================
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the relative difference [(h1-h2)/h2].
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathbf{H\,\,1}$",
|
|
33
|
+
h2_label=r"$\mathbf{H\,\,2}$",
|
|
34
|
+
comparison="relative_difference", # <--
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_relative_difference.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Ratio, split errors
|
|
3
|
+
===================
|
|
4
|
+
|
|
5
|
+
Compare two 1D histograms using the ratio [h1/h2] method and split the errors.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
name = "variable_1"
|
|
13
|
+
|
|
14
|
+
x1 = df[name][df["category"] == 2]
|
|
15
|
+
x2 = df[name][df["category"] == 3]
|
|
16
|
+
|
|
17
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
18
|
+
|
|
19
|
+
from plothist import make_hist
|
|
20
|
+
|
|
21
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
22
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
23
|
+
|
|
24
|
+
###
|
|
25
|
+
from plothist import plot_two_hist_comparison
|
|
26
|
+
|
|
27
|
+
fig, ax_main, ax_comparison = plot_two_hist_comparison(
|
|
28
|
+
h1,
|
|
29
|
+
h2,
|
|
30
|
+
xlabel=name,
|
|
31
|
+
ylabel="Entries",
|
|
32
|
+
h1_label=r"$\mathbf{h1}$",
|
|
33
|
+
h2_label=r"$\mathbf{h2}$",
|
|
34
|
+
comparison="split_ratio",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
fig.savefig("1d_comparison_split_ratio.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Multiple histograms
|
|
3
|
+
===================
|
|
4
|
+
|
|
5
|
+
Plot multiple histograms on the same plot using ``plot_hist()``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
###
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
|
|
15
|
+
from plothist import make_hist, plot_hist
|
|
16
|
+
|
|
17
|
+
name = "variable_1"
|
|
18
|
+
category = "category"
|
|
19
|
+
|
|
20
|
+
x1 = df[name][df[category] == 1]
|
|
21
|
+
x2 = df[name][df[category] == 2]
|
|
22
|
+
|
|
23
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
24
|
+
|
|
25
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
26
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
27
|
+
|
|
28
|
+
fig, ax = plt.subplots()
|
|
29
|
+
|
|
30
|
+
plot_hist(h1, ax=ax, histtype="step", linewidth=1.2, label="c1")
|
|
31
|
+
plot_hist(h2, ax=ax, histtype="step", linewidth=1.2, label="c2")
|
|
32
|
+
|
|
33
|
+
ax.set_xlabel(name)
|
|
34
|
+
ax.set_ylabel("Entries")
|
|
35
|
+
ax.set_xlim(x_range)
|
|
36
|
+
ax.legend()
|
|
37
|
+
|
|
38
|
+
fig.savefig("1d_elt1.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Stack histograms
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
Stack two 1D histograms with ``plot_hist()``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
import matplotlib.pyplot as plt
|
|
13
|
+
|
|
14
|
+
from plothist import make_hist, plot_hist
|
|
15
|
+
|
|
16
|
+
name = "variable_1"
|
|
17
|
+
category = "category"
|
|
18
|
+
|
|
19
|
+
x1 = df[name][df[category] == 1]
|
|
20
|
+
x2 = df[name][df[category] == 2]
|
|
21
|
+
|
|
22
|
+
x_range = (min(*x1, *x2), max(*x1, *x2))
|
|
23
|
+
|
|
24
|
+
h1 = make_hist(x1, bins=50, range=x_range)
|
|
25
|
+
h2 = make_hist(x2, bins=50, range=x_range)
|
|
26
|
+
|
|
27
|
+
###
|
|
28
|
+
fig, ax = plt.subplots()
|
|
29
|
+
|
|
30
|
+
plot_hist(
|
|
31
|
+
[h1, h2],
|
|
32
|
+
label=["c1", "c2"],
|
|
33
|
+
ax=ax,
|
|
34
|
+
edgecolor="black",
|
|
35
|
+
linewidth=0.5,
|
|
36
|
+
histtype="stepfilled",
|
|
37
|
+
stacked=True,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
ax.set_xlabel(name)
|
|
41
|
+
ax.set_ylabel("Entries")
|
|
42
|
+
ax.set_xlim(x_range)
|
|
43
|
+
ax.legend()
|
|
44
|
+
|
|
45
|
+
fig.savefig("1d_elt1_stacked.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Histogram with uncertainties
|
|
3
|
+
============================
|
|
4
|
+
|
|
5
|
+
Plot a 1D histogram with error bars using ``plot_error_hist()``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
###
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
|
|
15
|
+
from plothist import make_hist, plot_error_hist
|
|
16
|
+
|
|
17
|
+
name = "variable_1"
|
|
18
|
+
category = "category"
|
|
19
|
+
|
|
20
|
+
x1 = df[name][df[category] == 3]
|
|
21
|
+
|
|
22
|
+
h1 = make_hist(x1)
|
|
23
|
+
|
|
24
|
+
fig, ax = plt.subplots()
|
|
25
|
+
|
|
26
|
+
plot_error_hist(h1, ax=ax, color="black", label="$h1_{err}$")
|
|
27
|
+
|
|
28
|
+
ax.set_xlabel(name)
|
|
29
|
+
ax.set_ylabel("Entries")
|
|
30
|
+
ax.set_ylim(ymin=0)
|
|
31
|
+
ax.legend()
|
|
32
|
+
|
|
33
|
+
fig.savefig("1d_elt2.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Histogram
|
|
3
|
+
=========
|
|
4
|
+
|
|
5
|
+
Plot a 1D histogram with ``plot_hist()``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
###
|
|
13
|
+
import matplotlib.pyplot as plt
|
|
14
|
+
|
|
15
|
+
from plothist import make_hist, plot_hist
|
|
16
|
+
|
|
17
|
+
name = "variable_0"
|
|
18
|
+
|
|
19
|
+
fig, ax = plt.subplots()
|
|
20
|
+
|
|
21
|
+
h = make_hist(df[name])
|
|
22
|
+
|
|
23
|
+
plot_hist(h, ax=ax)
|
|
24
|
+
|
|
25
|
+
ax.set_xlabel(name)
|
|
26
|
+
ax.set_ylabel("Entries")
|
|
27
|
+
|
|
28
|
+
fig.savefig("1d_hist_simple.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Integer categories
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
Plot a 1D histogram with integer categories.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
###
|
|
9
|
+
import boost_histogram as bh
|
|
10
|
+
import matplotlib.pyplot as plt
|
|
11
|
+
|
|
12
|
+
from plothist import plot_hist
|
|
13
|
+
|
|
14
|
+
# 3 integer categories
|
|
15
|
+
int_categories = [-10, 5, 72]
|
|
16
|
+
|
|
17
|
+
# Integer category axis with 3 bins
|
|
18
|
+
axis = bh.axis.IntCategory(categories=int_categories)
|
|
19
|
+
|
|
20
|
+
# 6 data points,
|
|
21
|
+
data = [-10, -10, 5, 72, 72, 72]
|
|
22
|
+
|
|
23
|
+
# Create and fill the histogram
|
|
24
|
+
h = bh.Histogram(axis, storage=bh.storage.Weight())
|
|
25
|
+
h.fill(data)
|
|
26
|
+
|
|
27
|
+
# Plot the histogram
|
|
28
|
+
fig, ax = plt.subplots()
|
|
29
|
+
|
|
30
|
+
plot_hist(h, ax=ax)
|
|
31
|
+
|
|
32
|
+
# Set the x-ticks to the middle of the bins and label them
|
|
33
|
+
ax.set_xticks([i + 0.5 for i in range(len(int_categories))])
|
|
34
|
+
ax.set_xticklabels(int_categories)
|
|
35
|
+
ax.minorticks_off()
|
|
36
|
+
|
|
37
|
+
ax.set_xlabel("Integer Category")
|
|
38
|
+
ax.set_ylabel("Entries")
|
|
39
|
+
ax.set_xlim(0, len(int_categories))
|
|
40
|
+
|
|
41
|
+
fig.savefig("1d_int_category.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Mean histogram (profile)
|
|
3
|
+
========================
|
|
4
|
+
|
|
5
|
+
Plot a 1D mean histogram (profile).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
###
|
|
9
|
+
import boost_histogram as bh
|
|
10
|
+
import matplotlib.pyplot as plt
|
|
11
|
+
|
|
12
|
+
from plothist import plot_error_hist
|
|
13
|
+
|
|
14
|
+
# Regular axis with 3 bins from -1 to 1
|
|
15
|
+
axis = bh.axis.Regular(3, -1, 1)
|
|
16
|
+
|
|
17
|
+
# 6 data points, two in each bin
|
|
18
|
+
data = [-0.5, -0.5, 0.0, 0.0, 0.5, 0.5]
|
|
19
|
+
sample = [0, 100, 40, 60, 0, 20]
|
|
20
|
+
weights = [1, 1, 1, 1, 1, 1]
|
|
21
|
+
|
|
22
|
+
h = bh.Histogram(axis, storage=bh.storage.WeightedMean())
|
|
23
|
+
h.fill(data, weight=weights, sample=sample)
|
|
24
|
+
|
|
25
|
+
fig, ax = plt.subplots()
|
|
26
|
+
|
|
27
|
+
plot_error_hist(h, ax=ax)
|
|
28
|
+
|
|
29
|
+
ax.set_xlabel("Variable")
|
|
30
|
+
ax.set_ylabel("Mean")
|
|
31
|
+
ax.set_xlim(-1, 1)
|
|
32
|
+
|
|
33
|
+
fig.savefig("1d_profile.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Side-by-side categories
|
|
3
|
+
=======================
|
|
4
|
+
|
|
5
|
+
Plot multiple 1D histograms with categories side by side.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
###
|
|
9
|
+
import boost_histogram as bh
|
|
10
|
+
import matplotlib.pyplot as plt
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from plothist import plot_hist
|
|
14
|
+
|
|
15
|
+
rng = np.random.default_rng(8311311)
|
|
16
|
+
|
|
17
|
+
# String categories
|
|
18
|
+
categories = ["A", "B", "C"]
|
|
19
|
+
|
|
20
|
+
# Axis with the 3 bins
|
|
21
|
+
axis = bh.axis.StrCategory(categories=categories)
|
|
22
|
+
|
|
23
|
+
## Works also with integers
|
|
24
|
+
# categories = [-5, 10, 137]
|
|
25
|
+
# axis = bh.axis.IntCategory(categories=categories)
|
|
26
|
+
|
|
27
|
+
# Generate data for 3 histograms
|
|
28
|
+
data = [
|
|
29
|
+
rng.choice(categories, 20),
|
|
30
|
+
rng.choice(categories, 30),
|
|
31
|
+
rng.choice(categories, 40),
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
# Create and fill the histograms
|
|
35
|
+
histos = [bh.Histogram(axis, storage=bh.storage.Weight()) for _ in range(len(data))]
|
|
36
|
+
histos = [histo.fill(data[i]) for i, histo in enumerate(histos)]
|
|
37
|
+
|
|
38
|
+
labels = [f"$h_{{{i}}}$" for i in range(len(histos))]
|
|
39
|
+
|
|
40
|
+
# Plot the histogram
|
|
41
|
+
fig, ax = plt.subplots()
|
|
42
|
+
|
|
43
|
+
# Use a specificity of matplotlib: when a list of histograms is given, it will plot them side by side unless stacked=True or histtype is a "step" type.
|
|
44
|
+
plot_hist(histos, ax=ax, label=labels)
|
|
45
|
+
|
|
46
|
+
# Set the x-ticks to the middle of the bins and label them
|
|
47
|
+
ax.set_xlim(0, len(categories))
|
|
48
|
+
ax.set_xticks([i + 0.5 for i in range(len(categories))])
|
|
49
|
+
ax.set_xticklabels(categories)
|
|
50
|
+
ax.minorticks_off()
|
|
51
|
+
# Get nice looking y-axis ticks
|
|
52
|
+
ax.set_ylim(top=int(np.max([np.max(histo.values()) for histo in histos]) * 1.5))
|
|
53
|
+
|
|
54
|
+
ax.set_xlabel("Category")
|
|
55
|
+
ax.set_ylabel("Entries")
|
|
56
|
+
ax.legend()
|
|
57
|
+
|
|
58
|
+
fig.savefig("1d_side_by_side.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""
|
|
2
|
+
String categories
|
|
3
|
+
=================
|
|
4
|
+
|
|
5
|
+
Plot a 1D histogram with string categories.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
###
|
|
9
|
+
import boost_histogram as bh
|
|
10
|
+
import matplotlib.pyplot as plt
|
|
11
|
+
|
|
12
|
+
from plothist import plot_hist
|
|
13
|
+
|
|
14
|
+
# 3 str categories
|
|
15
|
+
str_categories = ["a", "b", "c"]
|
|
16
|
+
|
|
17
|
+
# String category axis with 3 bins
|
|
18
|
+
axis = bh.axis.StrCategory(categories=str_categories)
|
|
19
|
+
|
|
20
|
+
# 6 data points,
|
|
21
|
+
data = ["a", "a", "a", "b", "b", "c"]
|
|
22
|
+
|
|
23
|
+
# Create and fill the histogram
|
|
24
|
+
h = bh.Histogram(axis, storage=bh.storage.Weight())
|
|
25
|
+
h.fill(data)
|
|
26
|
+
|
|
27
|
+
# Plot the histogram
|
|
28
|
+
fig, ax = plt.subplots()
|
|
29
|
+
|
|
30
|
+
plot_hist(h, ax=ax)
|
|
31
|
+
|
|
32
|
+
# Set the x-ticks to the middle of the bins and label them
|
|
33
|
+
ax.set_xticks([i + 0.5 for i in range(len(str_categories))])
|
|
34
|
+
ax.set_xticklabels(str_categories)
|
|
35
|
+
ax.minorticks_off()
|
|
36
|
+
|
|
37
|
+
ax.set_xlabel("String Category")
|
|
38
|
+
ax.set_ylabel("Entries")
|
|
39
|
+
ax.set_xlim(0, len(str_categories))
|
|
40
|
+
|
|
41
|
+
fig.savefig("1d_str_category.svg", bbox_inches="tight")
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2D histograms
|
|
3
|
+
=============
|
|
4
|
+
|
|
5
|
+
Plot multiple 2D histograms with the variable registry.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
###
|
|
14
|
+
import os
|
|
15
|
+
import time
|
|
16
|
+
from itertools import combinations
|
|
17
|
+
|
|
18
|
+
from plothist import (
|
|
19
|
+
create_variable_registry,
|
|
20
|
+
get_variable_from_registry,
|
|
21
|
+
make_2d_hist,
|
|
22
|
+
plot_2d_hist,
|
|
23
|
+
update_variable_registry_ranges,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# No need to redo this step if the registry was already created before
|
|
27
|
+
variable_keys = ["variable_0", "variable_1", "variable_2"]
|
|
28
|
+
unique_id = str(int(time.time() * 1000))[-8:] # unique ID based on current time
|
|
29
|
+
temporary_registry_path = f"./_temporary_variable_registry_{unique_id}.yaml"
|
|
30
|
+
create_variable_registry(variable_keys, path=temporary_registry_path)
|
|
31
|
+
update_variable_registry_ranges(df, variable_keys, path=temporary_registry_path)
|
|
32
|
+
|
|
33
|
+
# Get all the correlation plot between the variables
|
|
34
|
+
variable_keys_combinations = list(combinations(variable_keys, 2))
|
|
35
|
+
|
|
36
|
+
figs = []
|
|
37
|
+
|
|
38
|
+
for variable_keys_combination in variable_keys_combinations:
|
|
39
|
+
variable0 = get_variable_from_registry(
|
|
40
|
+
variable_keys_combination[0], path=temporary_registry_path
|
|
41
|
+
)
|
|
42
|
+
variable1 = get_variable_from_registry(
|
|
43
|
+
variable_keys_combination[1], path=temporary_registry_path
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
h = make_2d_hist(
|
|
47
|
+
[df[variable0["name"]], df[variable1["name"]]],
|
|
48
|
+
bins=(variable0["bins"], variable1["bins"]),
|
|
49
|
+
range=(variable0["range"], variable1["range"]),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
fig, ax, ax_colorbar = plot_2d_hist(h, colorbar_kwargs={"label": "Entries"})
|
|
53
|
+
|
|
54
|
+
ax.set_xlabel(variable0["name"])
|
|
55
|
+
ax.set_ylabel(variable1["name"])
|
|
56
|
+
|
|
57
|
+
ax.set_xlim(variable0["range"])
|
|
58
|
+
ax.set_ylim(variable1["range"])
|
|
59
|
+
|
|
60
|
+
figs.append(fig)
|
|
61
|
+
|
|
62
|
+
for i, fig in enumerate(figs):
|
|
63
|
+
fig.savefig(f"2d_hist_correlations_{i}.svg", bbox_inches="tight")
|
|
64
|
+
|
|
65
|
+
os.remove(temporary_registry_path)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
2D histogram
|
|
3
|
+
============
|
|
4
|
+
|
|
5
|
+
Plot a 2D histogram with ``plot_2d_hist()``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from plothist_utils import get_dummy_data
|
|
9
|
+
|
|
10
|
+
df = get_dummy_data()
|
|
11
|
+
|
|
12
|
+
###
|
|
13
|
+
from plothist import make_2d_hist, plot_2d_hist
|
|
14
|
+
|
|
15
|
+
name_x = "variable_0"
|
|
16
|
+
name_y = "variable_1"
|
|
17
|
+
|
|
18
|
+
h = make_2d_hist([df[name_x], df[name_y]], bins=[10, 10])
|
|
19
|
+
|
|
20
|
+
fig, ax, ax_colorbar = plot_2d_hist(h, colorbar_kwargs={"label": "Entries"})
|
|
21
|
+
|
|
22
|
+
ax.set_xlabel(name_x)
|
|
23
|
+
ax.set_ylabel(name_y)
|
|
24
|
+
|
|
25
|
+
ax.set_xlim(-9, 9)
|
|
26
|
+
ax.set_ylim(-9, 9)
|
|
27
|
+
|
|
28
|
+
fig.savefig("2d_hist_simple.svg", bbox_inches="tight")
|