plothist 1.6.0__py3-none-any.whl → 1.7.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 CHANGED
@@ -9,12 +9,7 @@ from .comparison import (
9
9
  get_ratio,
10
10
  get_ratio_variances,
11
11
  )
12
- from .histogramming import (
13
- create_axis,
14
- flatten_2d_hist,
15
- make_2d_hist,
16
- make_hist,
17
- )
12
+ from .histogramming import create_axis, flatten_2d_hist, make_2d_hist, make_hist
18
13
  from .plothist_style import (
19
14
  add_luminosity,
20
15
  add_text,
@@ -43,6 +38,7 @@ from .variable_registry import (
43
38
  get_variable_from_registry,
44
39
  remove_variable_registry_parameters,
45
40
  update_variable_registry,
41
+ update_variable_registry_binning,
46
42
  update_variable_registry_ranges,
47
43
  )
48
44
 
@@ -81,6 +77,7 @@ __all__ = [
81
77
  "set_fitting_ylabel_fontsize",
82
78
  "set_style",
83
79
  "update_variable_registry",
80
+ "update_variable_registry_binning",
84
81
  "update_variable_registry_ranges",
85
82
  ]
86
83
 
plothist/_version.py CHANGED
@@ -1,7 +1,14 @@
1
1
  # file generated by setuptools-scm
2
2
  # don't change, don't track in version control
3
3
 
4
- __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
5
12
 
6
13
  TYPE_CHECKING = False
7
14
  if TYPE_CHECKING:
@@ -9,13 +16,19 @@ if TYPE_CHECKING:
9
16
  from typing import Union
10
17
 
11
18
  VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
12
20
  else:
13
21
  VERSION_TUPLE = object
22
+ COMMIT_ID = object
14
23
 
15
24
  version: str
16
25
  __version__: str
17
26
  __version_tuple__: VERSION_TUPLE
18
27
  version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
19
30
 
20
- __version__ = version = '1.6.0'
21
- __version_tuple__ = version_tuple = (1, 6, 0)
31
+ __version__ = version = '1.7.0'
32
+ __version_tuple__ = version_tuple = (1, 7, 0)
33
+
34
+ __commit_id__ = commit_id = None
@@ -20,7 +20,7 @@ from plothist import (
20
20
  get_variable_from_registry,
21
21
  make_2d_hist,
22
22
  plot_2d_hist,
23
- update_variable_registry_ranges,
23
+ update_variable_registry_binning,
24
24
  )
25
25
 
26
26
  # No need to redo this step if the registry was already created before
@@ -28,7 +28,7 @@ variable_keys = ["variable_0", "variable_1", "variable_2"]
28
28
  unique_id = str(int(time.time() * 1000))[-8:] # unique ID based on current time
29
29
  temporary_registry_path = f"./_temporary_variable_registry_{unique_id}.yaml"
30
30
  create_variable_registry(variable_keys, path=temporary_registry_path)
31
- update_variable_registry_ranges(df, variable_keys, path=temporary_registry_path)
31
+ update_variable_registry_binning(df, variable_keys, path=temporary_registry_path)
32
32
 
33
33
  # Get all the correlation plot between the variables
34
34
  variable_keys_combinations = list(combinations(variable_keys, 2))
plothist/histogramming.py CHANGED
@@ -109,6 +109,7 @@ def make_hist(
109
109
  bins: int | list[float] | np.ndarray = 50,
110
110
  range: tuple[float | str, float | str] | None = None,
111
111
  weights: float | list[float] | np.ndarray = 1,
112
+ mute_warning: bool = False,
112
113
  ) -> bh.Histogram:
113
114
  """
114
115
  Create a histogram object and fill it with the provided data.
@@ -129,6 +130,8 @@ def make_hist(
129
130
  Weight(s) to apply to the data points (default is 1).
130
131
  If a float, a single weight is applied to all data points.
131
132
  If an array-like, weights are applied element-wise.
133
+ mute_warning : bool, optional
134
+ Whether to mute warnings about data outside the binning range (default is False).
132
135
 
133
136
  Returns
134
137
  -------
@@ -160,7 +163,7 @@ def make_hist(
160
163
  range_coverage = h.sum().value / n_data
161
164
 
162
165
  # Issue a warning if more than 1% of the data is outside of the binning range
163
- if range_coverage < 0.99:
166
+ if range_coverage < 0.99 and not mute_warning:
164
167
  warnings.warn(
165
168
  f"Only {100 * range_coverage:.2f}% of data contained in the binning range [{axis.edges[0]}, {axis.edges[-1]}].",
166
169
  category=RangeWarning,
@@ -177,6 +180,7 @@ def make_2d_hist(
177
180
  tuple[float | str, float | str] | None, tuple[float | str, float | str] | None
178
181
  ] = (None, None),
179
182
  weights: float | list[float] | np.ndarray = 1,
183
+ mute_warning: bool = False,
180
184
  ) -> bh.Histogram:
181
185
  """
182
186
  Create a 2D histogram object and fill it with the provided data.
@@ -198,6 +202,8 @@ def make_2d_hist(
198
202
  Weight(s) to apply to the data points (default is 1).
199
203
  If a float, a single weight is applied to all data points.
200
204
  If an array-like, weights are applied element-wise.
205
+ mute_warning : bool, optional
206
+ Whether to mute warnings about data outside the binning range (default is False).
201
207
 
202
208
  Returns
203
209
  -------
@@ -245,7 +251,7 @@ def make_2d_hist(
245
251
  range_coverage = h.sum().value / n_data
246
252
 
247
253
  # Issue a warning if more than 1% of the data is outside of the binning range
248
- if range_coverage < 0.99:
254
+ if range_coverage < 0.99 and not mute_warning:
249
255
  warnings.warn(
250
256
  f"Only {100 * range_coverage:.2f}% of data contained in the binning range ([{x_axis.edges[0]}, {x_axis.edges[-1]}], [{y_axis.edges[0]}, {y_axis.edges[-1]}]).",
251
257
  category=RangeWarning,
@@ -8,6 +8,7 @@ import os
8
8
  import warnings
9
9
 
10
10
  import boost_histogram as bh
11
+ import numpy as np
11
12
  import yaml
12
13
 
13
14
  from plothist.histogramming import create_axis
@@ -126,7 +127,7 @@ def create_variable_registry(
126
127
  {
127
128
  variable_key: {
128
129
  "name": variable_key,
129
- "bins": 50,
130
+ "bins": "auto",
130
131
  "range": ("min", "max"),
131
132
  "label": variable_key,
132
133
  "log": False,
@@ -259,25 +260,37 @@ def remove_variable_registry_parameters(
259
260
  _save_variable_registry(variable_registry, path=path)
260
261
 
261
262
 
262
- def update_variable_registry_ranges(
263
+ def update_variable_registry_ranges(*args, **kwargs):
264
+ warnings.warn(
265
+ "`update_variable_registry_ranges` is deprecated since v1.7.0 and will be removed in future versions. "
266
+ "Use `update_variable_registry_binning` instead.",
267
+ DeprecationWarning,
268
+ stacklevel=2,
269
+ )
270
+ return update_variable_registry_binning(*args, **kwargs)
271
+
272
+
273
+ def update_variable_registry_binning(
263
274
  data,
264
275
  variable_keys: list[str] | None = None,
265
276
  path: str = "./variable_registry.yaml",
266
277
  overwrite: bool = False,
267
278
  ) -> None:
268
279
  """
269
- Update the range parameters for multiple variables in the variable registry file.
280
+ Update both the bins and range parameters for multiple variables in the variable registry file.
270
281
 
271
282
  Parameters
272
283
  ----------
273
284
  data : numpy.ndarray or pandas.DataFrame
274
285
  A dataset containing the data for the variables.
275
286
  variable_keys : list[str]
276
- A list of variable keys for which to update the range parameters in the registry. The variable needs to have a bin and range properties in the registry. Default is None: all variables in the registry are updated.
287
+ A list of variable keys for which to update the parameters in the registry.
288
+ The variable needs to have a bin and range properties in the registry.
289
+ Default is None: all variables in the registry are updated.
277
290
  path : str, optional
278
291
  The path to the variable registry file (default is "./variable_registry.yaml").
279
292
  overwrite : bool, optional
280
- If True, the range parameters will be overwritten even if it's not equal to ("min", "max") (default is False).
293
+ If True, the bin and range parameters will be overwritten even if they differ from "auto" and ("min", "max") (default is False).
281
294
 
282
295
  Returns
283
296
  -------
@@ -302,13 +315,23 @@ def update_variable_registry_ranges(
302
315
  f"Variable {variable_key} does not have a name, bins or range property in the registry {path}."
303
316
  )
304
317
 
305
- range = ("min", "max") if overwrite else variable["range"]
318
+ bins = "auto" if overwrite else variable["bins"]
319
+ bin_number = len(np.histogram_bin_edges(data[variable["name"]], bins=bins)) - 1
306
320
 
307
- if tuple(range) == ("min", "max"):
308
- axis = create_axis(variable["bins"], tuple(range), data[variable["name"]])
321
+ range_val = ("min", "max") if overwrite else variable["range"]
322
+
323
+ if bins == "auto" or tuple(range_val) == ("min", "max"):
324
+ axis = create_axis(
325
+ bin_number,
326
+ tuple(range_val),
327
+ data[variable["name"]],
328
+ )
309
329
  if isinstance(axis, bh.axis.Regular):
310
330
  update_variable_registry(
311
- {"range": (float(axis.edges[0]), float(axis.edges[-1]))},
331
+ {
332
+ "bins": bin_number,
333
+ "range": (float(axis.edges[0]), float(axis.edges[-1])),
334
+ },
312
335
  [variable_key],
313
336
  path=path,
314
337
  overwrite=True,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plothist
3
- Version: 1.6.0
3
+ Version: 1.7.0
4
4
  Summary: Plot histograms in a scalable way and a beautiful style.
5
5
  Project-URL: Homepage, https://github.com/cyrraz/plothist
6
6
  Project-URL: Documentation, https://plothist.readthedocs.io/
@@ -1,13 +1,13 @@
1
- plothist/__init__.py,sha256=ikcYOZqMs4WKAJ2rM-3BnHu_CQxLlQCuc-iFo_a-Mns,2760
2
- plothist/_version.py,sha256=5FGJNp9Lkk9uOxeCjXpoCGBF79Ar6LGPOR7-atBqb_4,511
1
+ plothist/__init__.py,sha256=-cUpXXg2cCdfjcbYAQWHLUHq-5kLsxSWgEbgtZYjqBA,2817
2
+ plothist/_version.py,sha256=oGRWiKvEGHesjf5wCNHGVlYfAA3dInDJeL5EiMaru6A,704
3
3
  plothist/_version.pyi,sha256=o7uNL6MhuJoiqpEnriU7rBT6TmkJZA-i2qMoNz9YcgQ,82
4
4
  plothist/comparison.py,sha256=jkONOiCp8RNBk8V_VvwACdfJJqo89rK9NQW71XxJscc,19623
5
5
  plothist/default_style.mplstyle,sha256=7MmB2uiXmD_DSqFHeH1xxC-lTctBD_EASxMdSOsPep0,1574
6
- plothist/histogramming.py,sha256=o0RLdoEhxHA7Ws0bvK3DewsbQEu-QOtJNw5Md5AckHM,11474
6
+ plothist/histogramming.py,sha256=Q0KRQjdyZGXj7J-qlXgzUbb-s7duqZG4QD2BIuVNQes,11828
7
7
  plothist/plothist_style.py,sha256=bbYFc-qsrTfdbacCBAAzmiHJoRIh3toBomFfxtTRNMs,13255
8
8
  plothist/plotters.py,sha256=ncPZa34Fo1mbFxv0guFc2zEciX_JXGKJxeIfcUDaP6w,46336
9
9
  plothist/test_helpers.py,sha256=JXhxUdqMszkawxkU8cDPqipkSXNHfsKSfe3K-4frDrM,1379
10
- plothist/variable_registry.py,sha256=usVLoDLbIMzjeRDazIH0OIjQIUsh9RSJ9Ncnhn1V9qw,10783
10
+ plothist/variable_registry.py,sha256=lYQ1DxUXBtY_UlZcuvwf_XQllq5MdPFKBmIrnRTNauo,11536
11
11
  plothist/examples/README.rst,sha256=PVzkOQzVnNeWORxEv3NNv5XoSN2Y71D7SYzRkCqirfA,151
12
12
  plothist/examples/1d_hist/1d_comparison_asymmetry.py,sha256=Rp9gv6E5z9KgIhnraS9AjGSMgHLhSHd_u5L-vG0w-gU,757
13
13
  plothist/examples/1d_hist/1d_comparison_difference.py,sha256=FMKoTjMIQp6VsFXspVBy2AdxHPDnxhMfj9PCvE4qVjk,877
@@ -26,7 +26,7 @@ plothist/examples/1d_hist/1d_profile.py,sha256=otmerm64DNAYnRWaablQkQDgUVOvjLNDc
26
26
  plothist/examples/1d_hist/1d_side_by_side.py,sha256=sAHhBVnopINQscFaUpVI4KNs18e_1laHyrYBOlmU_fQ,1557
27
27
  plothist/examples/1d_hist/1d_str_category.py,sha256=2DtxfNMAlcZ6pYx44lP0-sgY4M73-R0aBH61uEJmKA0,880
28
28
  plothist/examples/1d_hist/README.rst,sha256=GT4-w9W-TDtjOqibOPcd6vYzAGO8bDsgxBRp3fD1uTw,100
29
- plothist/examples/2d_hist/2d_hist_correlations.py,sha256=OroqVDKjNlAiMVXZ1AvFarV3qESiFkL0dnnb_NFkI70,1834
29
+ plothist/examples/2d_hist/2d_hist_correlations.py,sha256=c9PMymxNn9Kz0STvDQ3Pro4ndv-1PVG5RZsJCS9gobA,1836
30
30
  plothist/examples/2d_hist/2d_hist_simple.py,sha256=1n5yqOJxHzD31njOk85dTjuXhkogCDIS4-EG63XcnQ0,521
31
31
  plothist/examples/2d_hist/2d_hist_simple_discrete_colormap.py,sha256=E1zeMIDP25R_ppkB-wDz7TxaLsxf7dCs87FrPTPWTAc,1000
32
32
  plothist/examples/2d_hist/2d_hist_uneven.py,sha256=kR53XrSx38efG1wHEI69BIcPKVQzJygkr7ax_CFzBIA,646
@@ -57,8 +57,8 @@ plothist/examples/utility/color_palette_hists.py,sha256=uIc6TrmjTj8EUif1Yj1wq4nX
57
57
  plothist/examples/utility/color_palette_squares.py,sha256=pNasgvZZApu-sCqhi5FTJAH3l6Px2cgB5RwJcQ1eF1U,2689
58
58
  plothist/examples/utility/matplotlib_vs_plothist_style.py,sha256=iEIfbFKmAN-PcDCzw_sBuhrfpes4I2wUVfC0r1vUHEw,2006
59
59
  plothist/examples/utility/uncertainty_types.py,sha256=r1yxzEvxn5Clv0ZIok9JjVh3RB-YQ_usWhFnpvl1els,3259
60
- plothist-1.6.0.dist-info/METADATA,sha256=WsoMGQrcmUasAx0UxEP9aGEw7LAk1eHQCrjUz6228fY,4737
61
- plothist-1.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
62
- plothist-1.6.0.dist-info/licenses/AUTHORS.md,sha256=02x3_8PNyTsXcRs0IlJeCTOmpGNRqymcJ71-2QtR37E,111
63
- plothist-1.6.0.dist-info/licenses/LICENSE,sha256=bfaEdGehofQDaw-zDdVMHNUKo1FrOm6oGUEF-ltrp6w,1523
64
- plothist-1.6.0.dist-info/RECORD,,
60
+ plothist-1.7.0.dist-info/METADATA,sha256=X_mWIcy0jZbKaLcNPGaoL2jR4y1RnBYcnpQw-FgqlqM,4737
61
+ plothist-1.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
62
+ plothist-1.7.0.dist-info/licenses/AUTHORS.md,sha256=-2hRQyzJdkGgYPu8J-xDAWCwiqomcR56uYuzlJ4yMJM,115
63
+ plothist-1.7.0.dist-info/licenses/LICENSE,sha256=bfaEdGehofQDaw-zDdVMHNUKo1FrOm6oGUEF-ltrp6w,1523
64
+ plothist-1.7.0.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ * Cyrille Praz ([@cyrraz](https://github.com/cyrraz))
2
+ * Tristan Fillinger ([@0ctagon](https://github.com/0ctagon))
@@ -1,2 +0,0 @@
1
- Cyrille Praz ([@cyrraz](https://github.com/cyrraz))
2
- Tristan Fillinger ([@0ctagon](https://github.com/0ctagon))