plothist 1.3.2__py3-none-any.whl → 1.4.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/plotters.py CHANGED
@@ -1,27 +1,30 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  Collection of functions to plot histograms
4
3
  """
5
4
 
6
- import numpy as np
5
+ from __future__ import annotations
6
+
7
+ import re
8
+
7
9
  import boost_histogram as bh
8
10
  import matplotlib.pyplot as plt
11
+ import numpy as np
9
12
  from matplotlib.transforms import Bbox
10
- import re
13
+
11
14
  from plothist.comparison import (
12
- get_comparison,
13
- get_asymmetrical_uncertainties,
14
15
  _check_binning_consistency,
15
16
  _check_uncertainty_type,
17
+ get_asymmetrical_uncertainties,
18
+ get_comparison,
16
19
  )
17
- from plothist.histogramming import _make_hist_from_function, _check_counting_histogram
20
+ from plothist.histogramming import _check_counting_histogram, _make_hist_from_function
18
21
  from plothist.plothist_style import set_fitting_ylabel_fontsize
19
22
 
20
23
 
21
24
  def create_comparison_figure(
22
25
  figsize=(6, 5),
23
26
  nrows=2,
24
- gridspec_kw={"height_ratios": [4, 1]},
27
+ gridspec_kw=None,
25
28
  hspace=0.15,
26
29
  ):
27
30
  """
@@ -34,7 +37,8 @@ def create_comparison_figure(
34
37
  nrows : int, optional
35
38
  Number of rows in the subplot grid. Default is 2.
36
39
  gridspec_kw : dict, optional
37
- Additional keyword arguments for the GridSpec. Default is {"height_ratios": [4, 1]}.
40
+ Additional keyword arguments for the GridSpec. Default is None.
41
+ If None is provided, this is set to {"height_ratios": [4, 1]}.
38
42
  hspace : float, optional
39
43
  Height spacing between subplots. Default is 0.15.
40
44
 
@@ -47,6 +51,8 @@ def create_comparison_figure(
47
51
  Array of Axes objects representing the subplots.
48
52
 
49
53
  """
54
+ if gridspec_kw is None:
55
+ gridspec_kw = {"height_ratios": [4, 1]}
50
56
  if figsize is None:
51
57
  figsize = plt.rcParams["figure.figsize"]
52
58
 
@@ -99,8 +105,8 @@ def plot_2d_hist(
99
105
  fig=None,
100
106
  ax=None,
101
107
  ax_colorbar=None,
102
- pcolormesh_kwargs={},
103
- colorbar_kwargs={},
108
+ pcolormesh_kwargs=None,
109
+ colorbar_kwargs=None,
104
110
  square_ax=True,
105
111
  ):
106
112
  """
@@ -117,12 +123,16 @@ def plot_2d_hist(
117
123
  ax_colorbar : matplotlib.axes.Axes
118
124
  The Axes instance for the colorbar. If fig, ax and ax_colorbar are None, a new figure will be created. Default is None.
119
125
  pcolormesh_kwargs : dict, optional
120
- Additional keyword arguments forwarded to ax.pcolormesh() (default is {}).
126
+ Additional keyword arguments forwarded to ax.pcolormesh(). Default is None.
121
127
  colorbar_kwargs : dict, optional
122
- Additional keyword arguments forwarded to ax.get_figure().colorbar() (default is {}).
128
+ Additional keyword arguments forwarded to ax.get_figure().colorbar(). Default is None.
123
129
  square_ax : bool, optional
124
130
  Whether to make the main ax square (default is True).
125
131
  """
132
+ if colorbar_kwargs is None:
133
+ colorbar_kwargs = {}
134
+ if pcolormesh_kwargs is None:
135
+ pcolormesh_kwargs = {}
126
136
  # Create copies of the kwargs arguments passed as lists/dicts to avoid modifying them
127
137
  pcolormesh_kwargs = pcolormesh_kwargs.copy()
128
138
  colorbar_kwargs = colorbar_kwargs.copy()
@@ -205,7 +215,7 @@ def plot_function(func, range, ax, stacked=False, npoints=1000, **kwargs):
205
215
  **kwargs,
206
216
  )
207
217
  else:
208
- if kwargs.get("labels", None) is None:
218
+ if kwargs.get("labels") is None:
209
219
  kwargs["labels"] = []
210
220
 
211
221
  if not isinstance(func, list):
@@ -228,9 +238,9 @@ def plot_2d_hist_with_projections(
228
238
  xlabel_y_projection=None,
229
239
  colorbar_label=None,
230
240
  offset_x_labels=False,
231
- pcolormesh_kwargs={},
232
- colorbar_kwargs={},
233
- plot_hist_kwargs={},
241
+ pcolormesh_kwargs=None,
242
+ colorbar_kwargs=None,
243
+ plot_hist_kwargs=None,
234
244
  figsize=(6, 6),
235
245
  ):
236
246
  """Plot a 2D histogram with projections on the x and y axes.
@@ -252,11 +262,11 @@ def plot_2d_hist_with_projections(
252
262
  offset_x_labels : bool, optional
253
263
  Whether to offset the x labels to avoid overlapping with the exponent label (i.e. "10^X") of the axis. Default is False.
254
264
  pcolormesh_kwargs : dict, optional
255
- Keyword arguments for the pcolormesh call. Default is {}.
265
+ Keyword arguments for the pcolormesh call. Default is None.
256
266
  colorbar_kwargs : dict, optional
257
- Keyword arguments for the colorbar call. Default is {}.
267
+ Keyword arguments for the colorbar call. Default is None.
258
268
  plot_hist_kwargs : dict, optional
259
- Keyword arguments for the plot_hist call (x and y projections). Default is {}.
269
+ Keyword arguments for the plot_hist call (x and y projections). Default is None.
260
270
  figsize : tuple, optional
261
271
  Figure size in inches. Default is (6, 6). To get square bins if the figure is not square shaped, be sure to set the bins and the ranges of the histogram according to the ratio of the figure width and height.
262
272
 
@@ -273,6 +283,12 @@ def plot_2d_hist_with_projections(
273
283
  ax_colorbar : matplotlib.axes.Axes
274
284
  The axes for the colorbar.
275
285
  """
286
+ if plot_hist_kwargs is None:
287
+ plot_hist_kwargs = {}
288
+ if colorbar_kwargs is None:
289
+ colorbar_kwargs = {}
290
+ if pcolormesh_kwargs is None:
291
+ pcolormesh_kwargs = {}
276
292
  _check_counting_histogram(hist)
277
293
 
278
294
  # Create copies of the kwargs arguments passed as lists/dicts to avoid modifying them
@@ -332,10 +348,7 @@ def plot_2d_hist_with_projections(
332
348
  ax_2d.set_ylim(ylim)
333
349
  ax_y_projection.set_ylim(ylim)
334
350
 
335
- if offset_x_labels:
336
- labelpad = 20
337
- else:
338
- labelpad = None
351
+ labelpad = 20 if offset_x_labels else None
339
352
 
340
353
  ax_2d.set_xlabel(xlabel, labelpad=labelpad)
341
354
  ax_2d.set_ylabel(ylabel)
@@ -738,8 +751,7 @@ def _get_math_text(text):
738
751
  match = re.search(r"\$(.*?)\$", text)
739
752
  if match:
740
753
  return match.group(1)
741
- else:
742
- return text
754
+ return text
743
755
 
744
756
 
745
757
  def _get_model_type(components):
@@ -764,24 +776,23 @@ def _get_model_type(components):
764
776
  """
765
777
  if all(isinstance(x, bh.Histogram) for x in components):
766
778
  return "histograms"
767
- elif all(callable(x) for x in components):
779
+ if all(callable(x) for x in components):
768
780
  return "functions"
769
- else:
770
- raise ValueError("All model components must be either histograms or functions.")
781
+ raise ValueError("All model components must be either histograms or functions.")
771
782
 
772
783
 
773
784
  def plot_model(
774
- stacked_components=[],
785
+ stacked_components=None,
775
786
  stacked_labels=None,
776
787
  stacked_colors=None,
777
- unstacked_components=[],
788
+ unstacked_components=None,
778
789
  unstacked_labels=None,
779
790
  unstacked_colors=None,
780
791
  xlabel=None,
781
792
  ylabel=None,
782
- stacked_kwargs={},
783
- unstacked_kwargs_list=[],
784
- model_sum_kwargs={"show": True, "label": "Model", "color": "navy"},
793
+ stacked_kwargs=None,
794
+ unstacked_kwargs_list=None,
795
+ model_sum_kwargs=None,
785
796
  function_range=None,
786
797
  model_uncertainty=True,
787
798
  model_uncertainty_label="Model stat. unc.",
@@ -794,13 +805,13 @@ def plot_model(
794
805
  Parameters
795
806
  ----------
796
807
  stacked_components : list of boost_histogram.Histogram, optional
797
- The list of histograms to be stacked composing the model. Default is [].
808
+ The list of histograms to be stacked composing the model. Default is None.
798
809
  stacked_labels : list of str, optional
799
810
  The labels of the model stacked components. Default is None.
800
811
  stacked_colors : list of str, optional
801
812
  The colors of the model stacked components. Default is None.
802
813
  unstacked_components : list of boost_histogram.Histogram, optional
803
- The list of histograms not to be stacked composing the model. Default is [].
814
+ The list of histograms not to be stacked composing the model. Default is None.
804
815
  unstacked_labels : list of str, optional
805
816
  The labels of the model unstacked components. Default is None.
806
817
  unstacked_colors : list of str, optional
@@ -810,14 +821,14 @@ def plot_model(
810
821
  ylabel : str, optional
811
822
  The label for the y-axis. Default is None.
812
823
  stacked_kwargs : dict, optional
813
- The keyword arguments used when plotting the stacked components in plot_hist() or plot_function(), one of which is called only once. Default is {}.
824
+ The keyword arguments used when plotting the stacked components in plot_hist() or plot_function(), one of which is called only once. Default is None.
814
825
  unstacked_kwargs_list : list of dict, optional
815
- The list of keyword arguments used when plotting the unstacked components in plot_hist() or plot_function(), one of which is called once for each unstacked component. Default is [].
826
+ The list of keyword arguments used when plotting the unstacked components in plot_hist() or plot_function(), one of which is called once for each unstacked component. Default is None.
816
827
  model_sum_kwargs : dict, optional
817
828
  The keyword arguments for the plot_hist() function for the sum of the model components.
818
829
  Has no effect if all the model components are stacked or if the model is one unstacked element.
819
830
  The special keyword "show" can be used with a boolean to specify whether to show or not the sum of the model components.
820
- Default is {"show": True, "label": "Model", "color": "navy"}.
831
+ Default is None. If None is provided, this is set to {"show": True, "label": "Model", "color": "navy"}.
821
832
  function_range : tuple, optional (mandatory if the model is made of functions)
822
833
  The range for the x-axis if the model is made of functions.
823
834
  model_uncertainty : bool, optional
@@ -838,6 +849,16 @@ def plot_model(
838
849
  The Axes object containing the plot.
839
850
 
840
851
  """
852
+ if model_sum_kwargs is None:
853
+ model_sum_kwargs = {"show": True, "label": "Model", "color": "navy"}
854
+ if unstacked_kwargs_list is None:
855
+ unstacked_kwargs_list = []
856
+ if stacked_kwargs is None:
857
+ stacked_kwargs = {}
858
+ if unstacked_components is None:
859
+ unstacked_components = []
860
+ if stacked_components is None:
861
+ stacked_components = []
841
862
 
842
863
  # Create copies of the kwargs arguments passed as lists/dicts to avoid modifying them
843
864
  stacked_kwargs = stacked_kwargs.copy()
@@ -980,18 +1001,18 @@ def plot_model(
980
1001
 
981
1002
  def plot_data_model_comparison(
982
1003
  data_hist,
983
- stacked_components=[],
1004
+ stacked_components=None,
984
1005
  stacked_labels=None,
985
1006
  stacked_colors=None,
986
- unstacked_components=[],
1007
+ unstacked_components=None,
987
1008
  unstacked_labels=None,
988
1009
  unstacked_colors=None,
989
1010
  xlabel=None,
990
1011
  ylabel=None,
991
1012
  data_label="Data",
992
- stacked_kwargs={},
993
- unstacked_kwargs_list=[],
994
- model_sum_kwargs={"show": True, "label": "Sum", "color": "navy"},
1013
+ stacked_kwargs=None,
1014
+ unstacked_kwargs_list=None,
1015
+ model_sum_kwargs=None,
995
1016
  model_uncertainty=True,
996
1017
  model_uncertainty_label="Model stat. unc.",
997
1018
  data_uncertainty_type="asymmetrical",
@@ -1009,13 +1030,13 @@ def plot_data_model_comparison(
1009
1030
  data_hist : boost_histogram.Histogram
1010
1031
  The histogram for the data.
1011
1032
  stacked_components : list of boost_histogram.Histogram, optional
1012
- The list of histograms to be stacked composing the model. Default is [].
1033
+ The list of histograms to be stacked composing the model. Default is None.
1013
1034
  stacked_labels : list of str, optional
1014
1035
  The labels of the model stacked components. Default is None.
1015
1036
  stacked_colors : list of str, optional
1016
1037
  The colors of the model stacked components. Default is None.
1017
1038
  unstacked_components : list of boost_histogram.Histogram, optional
1018
- The list of histograms not to be stacked composing the model. Default is [].
1039
+ The list of histograms not to be stacked composing the model. Default is None.
1019
1040
  unstacked_labels : list of str, optional
1020
1041
  The labels of the model unstacked components. Default is None.
1021
1042
  unstacked_colors : list of str, optional
@@ -1027,14 +1048,14 @@ def plot_data_model_comparison(
1027
1048
  data_label : str, optional
1028
1049
  The label for the data. Default is "Data".
1029
1050
  stacked_kwargs : dict, optional
1030
- The keyword arguments used when plotting the stacked components in plot_hist() or plot_function(), one of which is called only once. Default is {}.
1051
+ The keyword arguments used when plotting the stacked components in plot_hist() or plot_function(), one of which is called only once. Default is None.
1031
1052
  unstacked_kwargs_list : list of dict, optional
1032
- The list of keyword arguments used when plotting the unstacked components in plot_hist() or plot_function(), one of which is called once for each unstacked component. Default is [].
1053
+ The list of keyword arguments used when plotting the unstacked components in plot_hist() or plot_function(), one of which is called once for each unstacked component. Default is None.
1033
1054
  model_sum_kwargs : dict, optional
1034
1055
  The keyword arguments for the plot_hist() function for the sum of the model components.
1035
1056
  Has no effect if all the model components are stacked or if the model is one unstacked element.
1036
1057
  The special keyword "show" can be used with a boolean to specify whether to show or not the sum of the model components.
1037
- Default is {"show": True, "label": "Sum", "color": "navy"}.
1058
+ Default is None. If None is provided, this is set to {"show": True, "label": "Sum", "color": "navy"}.
1038
1059
  model_uncertainty : bool, optional
1039
1060
  If False, set the model uncertainties to zeros. Default is True.
1040
1061
  model_uncertainty_label : str, optional
@@ -1066,6 +1087,22 @@ def plot_data_model_comparison(
1066
1087
  plot_comparison : Plot the comparison between two histograms.
1067
1088
 
1068
1089
  """
1090
+ if model_sum_kwargs is None:
1091
+ model_sum_kwargs = {"show": True, "label": "Sum", "color": "navy"}
1092
+ if unstacked_kwargs_list is None:
1093
+ unstacked_kwargs_list = []
1094
+ if stacked_kwargs is None:
1095
+ stacked_kwargs = {}
1096
+ if unstacked_components is None:
1097
+ unstacked_components = []
1098
+ if stacked_components is None:
1099
+ stacked_components = []
1100
+
1101
+ # Create copies of the kwargs arguments passed as lists/dicts to avoid modifying them
1102
+ stacked_kwargs = stacked_kwargs.copy()
1103
+ unstacked_kwargs_list = unstacked_kwargs_list.copy()
1104
+ model_sum_kwargs = model_sum_kwargs.copy()
1105
+
1069
1106
  comparison_kwargs.setdefault("h1_label", data_label)
1070
1107
  comparison_kwargs.setdefault("h2_label", "Pred.")
1071
1108
  comparison_kwargs.setdefault("comparison", "split_ratio")
@@ -1078,8 +1115,8 @@ def plot_data_model_comparison(
1078
1115
  model_type = _get_model_type(model_components)
1079
1116
 
1080
1117
  if model_type == "histograms":
1081
- _check_binning_consistency(model_components + [data_hist])
1082
- for component in model_components + [data_hist]:
1118
+ _check_binning_consistency([*model_components, data_hist])
1119
+ for component in [*model_components, data_hist]:
1083
1120
  _check_counting_histogram(component)
1084
1121
 
1085
1122
  if fig is None and ax_main is None and ax_comparison is None:
@@ -1097,11 +1134,8 @@ def plot_data_model_comparison(
1097
1134
  raise ValueError(
1098
1135
  "Need to provide fig, ax_main and ax_comparison (or none of them)."
1099
1136
  )
1100
- else:
1101
- if plot_only is not None:
1102
- raise ValueError(
1103
- "Cannot provide fig, ax_main or ax_comparison with plot_only."
1104
- )
1137
+ elif plot_only is not None:
1138
+ raise ValueError("Cannot provide fig, ax_main or ax_comparison with plot_only.")
1105
1139
 
1106
1140
  plot_model(
1107
1141
  stacked_components=stacked_components,
@@ -1,2 +1,3 @@
1
- from .install_latin_modern_fonts import install_latin_modern_fonts
2
- from .make_examples import make_examples
1
+ from __future__ import annotations
2
+
3
+ from .make_examples import make_examples as make_examples
@@ -1,11 +1,15 @@
1
+ from __future__ import annotations
2
+
3
+ import hashlib
1
4
  import os
2
- import yaml
3
5
  import subprocess
4
- import plothist
5
- import hashlib
6
6
  import warnings
7
- import sys
7
+ from importlib import resources
8
+
9
+ import yaml
10
+ from packaging import version
8
11
 
12
+ import plothist
9
13
 
10
14
  _matplotlib_version = "3.10.0"
11
15
  _numpy_version = "2.0.0"
@@ -32,9 +36,7 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
32
36
 
33
37
  import matplotlib
34
38
 
35
- if tuple(map(int, matplotlib.__version__.split("."))) < tuple(
36
- map(int, _matplotlib_version.split("."))
37
- ):
39
+ if version.parse(matplotlib.__version__) < version.parse(_matplotlib_version):
38
40
  warnings.warn(
39
41
  f"svg behavior is not consistent across matplotlib versions. Please run this script with matplotlib {_matplotlib_version} or higher. Skipping.",
40
42
  stacklevel=2,
@@ -43,9 +45,7 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
43
45
 
44
46
  import numpy
45
47
 
46
- if tuple(map(int, numpy.__version__.split("."))) < tuple(
47
- map(int, _numpy_version.split("."))
48
- ):
48
+ if version.parse(numpy.__version__) < version.parse(_numpy_version):
49
49
  warnings.warn(
50
50
  f"svg behavior is not consistent across numpy versions. Please run this script with numpy {_numpy_version} or higher. Skipping.",
51
51
  stacklevel=2,
@@ -97,7 +97,7 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
97
97
  if k_plot == "all":
98
98
  plots_to_redo = python_files[:]
99
99
  break
100
- elif k_plot in ["1d", "2d", "model", "color"]:
100
+ if k_plot in ["1d", "2d", "model", "color"]:
101
101
  plots_to_redo.extend(
102
102
  [
103
103
  python_file
@@ -113,17 +113,10 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
113
113
  os.makedirs(temp_img_folder, exist_ok=True)
114
114
 
115
115
  # Get the metadata for the svg files
116
- if not os.path.exists(plothist_folder + "/.svg_metadata.yaml"):
117
- subprocess.run(
118
- [
119
- "wget",
120
- "-O",
121
- plothist_folder + "/.svg_metadata.yaml",
122
- "https://raw.githubusercontent.com/0ctagon/plothist-utils/dbf86375576fa2ca5c35ab3a35bba1ab7715a186/.svg_metadata.yaml",
123
- ]
124
- )
125
-
126
- with open(plothist_folder + "/.svg_metadata.yaml", "r") as f:
116
+ metadata_file = (
117
+ resources.files("plothist_utils") / "metadata" / ".svg_metadata.yaml"
118
+ )
119
+ with open(metadata_file) as f:
127
120
  svg_metadata = yaml.safe_load(f)
128
121
 
129
122
  svg_metadata = "metadata=" + str(svg_metadata)
@@ -134,11 +127,11 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
134
127
  img_hashes = {}
135
128
  for file in os.listdir(img_folder):
136
129
  if file.endswith(".svg"):
137
- with open(os.path.join(img_folder, file), "r") as f:
130
+ with open(os.path.join(img_folder, file)) as f:
138
131
  img_hashes[file] = hashlib.sha256(f.read().encode()).hexdigest()
139
132
 
140
133
  # Iterate through all subfolders and files in the source folder
141
- for root, dirs, files in os.walk(example_folder):
134
+ for root, _dirs, files in os.walk(example_folder):
142
135
  for file in files:
143
136
  if file not in plots_to_redo:
144
137
  continue
@@ -147,7 +140,7 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
147
140
  file_path = os.path.join(root, file)
148
141
  file_code = ""
149
142
 
150
- with open(file_path, "r") as f:
143
+ with open(file_path) as f:
151
144
  for line in f:
152
145
  if "savefig" in line:
153
146
  if file == "matplotlib_vs_plothist_style.py":
@@ -168,6 +161,7 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
168
161
  cwd=temp_img_folder,
169
162
  capture_output=True,
170
163
  text=True,
164
+ check=False,
171
165
  )
172
166
  if result.returncode != 0 and check_svg:
173
167
  fail(f"Error while redoing {file}:\n{result.stderr}\n{result.stdout}")
@@ -177,17 +171,19 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
177
171
  # Move the svg files to the img folder
178
172
  for file in os.listdir(temp_img_folder):
179
173
  if file.endswith(".svg"):
180
- subprocess.run(["mv", os.path.join(temp_img_folder, file), img_folder])
174
+ subprocess.run(
175
+ ["mv", os.path.join(temp_img_folder, file), img_folder], check=False
176
+ )
181
177
 
182
178
  # Remove the temp folder
183
- subprocess.run(["rm", "-rf", temp_img_folder])
179
+ subprocess.run(["rm", "-rf", temp_img_folder], check=False)
184
180
 
185
181
  # Check that the svg files have not changed
186
182
  if check_svg:
187
183
  new_img_hashes = {}
188
184
  for file in os.listdir(img_folder):
189
185
  if file.endswith(".svg"):
190
- with open(os.path.join(img_folder, file), "r") as f:
186
+ with open(os.path.join(img_folder, file)) as f:
191
187
  new_img_hashes[file] = hashlib.sha256(f.read().encode()).hexdigest()
192
188
 
193
189
  # Check that the hashes are the same and print the ones that are different
@@ -204,6 +200,9 @@ def make_examples(no_input=False, check_svg=False, print_code=False):
204
200
  fail(
205
201
  f"The number of images has changed. Please run `plothist_make_examples`, check the new images and commit them if they are correct. New images:\n{set(new_img_hashes.keys()) - set(img_hashes.keys())}"
206
202
  )
203
+ return None
204
+ return None
205
+ return None
207
206
 
208
207
 
209
208
  if __name__ == "__main__":
@@ -1,11 +1,15 @@
1
- # -*- coding: utf-8 -*-
2
1
  """
3
2
  Collection of functions to manage the variable registry
4
3
  """
5
- import yaml
4
+
5
+ from __future__ import annotations
6
+
6
7
  import os
7
8
  import warnings
9
+
8
10
  import boost_histogram as bh
11
+ import yaml
12
+
9
13
  from plothist.histogramming import create_axis
10
14
 
11
15
 
@@ -27,9 +31,8 @@ def _check_if_variable_registry_exists(path):
27
31
  RuntimeError
28
32
  If the variable registry file does not exist.
29
33
  """
30
- if not os.path.exists(path):
31
- if path == "./variable_registry.yaml":
32
- raise RuntimeError("Did you forgot to run create_variable_registry()?")
34
+ if not os.path.exists(path) and path == "./variable_registry.yaml":
35
+ raise RuntimeError("Did you forgot to run create_variable_registry()?")
33
36
 
34
37
 
35
38
  def _save_variable_registry(variable_registry, path="./variable_registry.yaml"):
@@ -106,13 +109,13 @@ def create_variable_registry(
106
109
  with open(path, "w") as f:
107
110
  pass
108
111
 
109
- with open(path, "r") as f:
112
+ with open(path) as f:
110
113
  variable_registry = yaml.safe_load(f)
111
114
  if variable_registry is None:
112
115
  variable_registry = {}
113
116
 
114
117
  for variable_key in variable_keys:
115
- if variable_key not in variable_registry.keys() or reset:
118
+ if variable_key not in variable_registry or reset:
116
119
  if custom_dict is not None:
117
120
  variable_registry.update({variable_key: custom_dict})
118
121
  else:
@@ -158,7 +161,7 @@ def get_variable_from_registry(variable_key, path="./variable_registry.yaml"):
158
161
 
159
162
  _check_if_variable_registry_exists(path)
160
163
 
161
- with open(path, "r") as f:
164
+ with open(path) as f:
162
165
  variable_registry = yaml.safe_load(f)
163
166
  return variable_registry[variable_key]
164
167
 
@@ -186,7 +189,7 @@ def update_variable_registry(
186
189
  """
187
190
  _check_if_variable_registry_exists(path)
188
191
 
189
- with open(path, "r") as f:
192
+ with open(path) as f:
190
193
  variable_registry = yaml.safe_load(f)
191
194
 
192
195
  if variable_keys is None:
@@ -194,7 +197,7 @@ def update_variable_registry(
194
197
 
195
198
  for variable_key in variable_keys:
196
199
  for key, value in dictionary.items():
197
- if key not in variable_registry[variable_key].keys() or overwrite:
200
+ if key not in variable_registry[variable_key] or overwrite:
198
201
  variable_registry[variable_key].update({key: value})
199
202
 
200
203
  _save_variable_registry(variable_registry, path=path)
@@ -221,7 +224,7 @@ def remove_variable_registry_parameters(
221
224
  """
222
225
  _check_if_variable_registry_exists(path)
223
226
 
224
- with open(path, "r") as f:
227
+ with open(path) as f:
225
228
  variable_registry = yaml.safe_load(f)
226
229
 
227
230
  if variable_keys is None:
@@ -229,7 +232,7 @@ def remove_variable_registry_parameters(
229
232
 
230
233
  for variable_key in variable_keys:
231
234
  for parameter in parameters:
232
- if parameter in variable_registry[variable_key].keys():
235
+ if parameter in variable_registry[variable_key]:
233
236
  _ = variable_registry[variable_key].pop(parameter)
234
237
  else:
235
238
  warnings.warn(
@@ -272,13 +275,13 @@ def update_variable_registry_ranges(
272
275
  _check_if_variable_registry_exists(path)
273
276
 
274
277
  if variable_keys is None:
275
- with open(path, "r") as f:
278
+ with open(path) as f:
276
279
  variable_registry = yaml.safe_load(f)
277
280
  variable_keys = list(variable_registry.keys())
278
281
 
279
282
  for variable_key in variable_keys:
280
283
  variable = get_variable_from_registry(variable_key, path=path)
281
- if not all(key in variable.keys() for key in ["bins", "range", "name"]):
284
+ if not all(key in variable for key in ["bins", "range", "name"]):
282
285
  raise RuntimeError(
283
286
  f"Variable {variable_key} does not have a name, bins or range property in the registry {path}."
284
287
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plothist
3
- Version: 1.3.2
3
+ Version: 1.4.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/
@@ -19,13 +19,10 @@ Requires-Python: >=3.9
19
19
  Requires-Dist: boost-histogram>=1.4.0
20
20
  Requires-Dist: matplotlib>=3.0
21
21
  Requires-Dist: numpy>=1.14.5
22
+ Requires-Dist: plothist-utils>=0.0.1
22
23
  Requires-Dist: pyyaml>=5.3.1
23
24
  Requires-Dist: requests>=2.25.0
24
25
  Requires-Dist: scipy>=1.6.0
25
- Provides-Extra: dev
26
- Requires-Dist: pre-commit>=4.1.0; extra == 'dev'
27
- Provides-Extra: test
28
- Requires-Dist: pytest>=8.3.5; extra == 'test'
29
26
  Description-Content-Type: text/x-rst
30
27
 
31
28
 
@@ -49,8 +46,11 @@ plothist
49
46
  :width: 320
50
47
 
51
48
 
52
- |GitHub Project| |PyPI version| |Docs from main| |Discussion| |DOI| |Code style: black|
49
+ |GitHub Project| |PyPI version| |Docs from main| |Discussion| |DOI| |Linter|
53
50
 
51
+ |GitHub Actions Status: CI| |GitHub Actions Status: CD| |pre-commit.ci Status| |Code Coverage|
52
+
53
+ This package is a wrapper around `matplotlib <https://matplotlib.org/>`_.
54
54
 
55
55
  **Advantages of the package**: scalability, style and user-friendly way of managing variables and a stunning `example gallery <https://plothist.readthedocs.io/en/latest/example_gallery/>`_.
56
56
 
@@ -73,13 +73,21 @@ plothist
73
73
 
74
74
  .. |GitHub Project| image:: https://img.shields.io/badge/GitHub--blue?style=social&logo=GitHub
75
75
  :target: https://github.com/cyrraz/plothist
76
- .. |PyPI version| image:: https://badge.fury.io/py/plothist.svg
76
+ .. |PyPI version| image:: https://badge.fury.io/py/plothist.svg?style=flat-square
77
77
  :target: https://badge.fury.io/py/plothist
78
- .. |Docs from main| image:: https://img.shields.io/badge/docs-main-blue.svg
78
+ .. |Docs from main| image:: https://img.shields.io/badge/docs-main-blue.svg?style=platic
79
79
  :target: https://plothist.readthedocs.io/en/main/
80
- .. |Discussion| image:: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
80
+ .. |Discussion| image:: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github?style=flat-square
81
81
  :target: https://github.com/cyrraz/plothist/discussions
82
- .. |DOI| image:: https://zenodo.org/badge/647069945.svg
82
+ .. |DOI| image:: https://zenodo.org/badge/647069945.svg?style=flat-square
83
83
  :target: https://zenodo.org/doi/10.5281/zenodo.10995667
84
- .. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
85
- :target: https://github.com/psf/black
84
+ .. |Linter| image:: https://img.shields.io/badge/Linter-Ruff-brightgreen?style=platic
85
+ :target: https://github.com/charliermarsh/ruff
86
+ .. |GitHub Actions Status: CI| image:: https://github.com/cyrraz/plothist/actions/workflows/ci.yaml/badge.svg?style=flat-square
87
+ :target: https://github.com/cyrraz/plothist/actions/workflows/ci.yaml?query=branch%3Amain
88
+ .. |GitHub Actions Status: CD| image:: https://github.com/cyrraz/plothist/actions/workflows/cd.yaml/badge.svg?style=flat-square
89
+ :target: https://github.com/cyrraz/plothist/actions/workflows/cd.yaml?query=branch%3Amain
90
+ .. |pre-commit.ci Status| image:: https://results.pre-commit.ci/badge/github/cyrraz/plothist/main.svg?style=flat-square
91
+ :target: https://results.pre-commit.ci/latest/github/cyrraz/plothist/main
92
+ .. |Code Coverage| image:: https://codecov.io/gh/cyrraz/plothist/branch/main/graph/badge.svg?style=flat-square
93
+ :target: https://codecov.io/gh/cyrraz/plothist
@@ -0,0 +1,17 @@
1
+ plothist/__init__.py,sha256=00yQZBIlyvZxdimTgPMHK_ZH5pNVadyi-fu6ezuXRQs,2760
2
+ plothist/_version.py,sha256=rcWNYDlh913lujUvTfOu9iOIPdrTXg64R9wl7ENLjFU,511
3
+ plothist/_version.pyi,sha256=o7uNL6MhuJoiqpEnriU7rBT6TmkJZA-i2qMoNz9YcgQ,82
4
+ plothist/comparison.py,sha256=dHB83vz18RdDNR5PBDLtV2kzjD1c2WGB-0nD0g3BOBI,17464
5
+ plothist/default_style.mplstyle,sha256=7MmB2uiXmD_DSqFHeH1xxC-lTctBD_EASxMdSOsPep0,1574
6
+ plothist/histogramming.py,sha256=Z5XgN3xsIxLQX15yf_Wyf0uTOb9aKAJJJ_HK1L1HpGM,10328
7
+ plothist/plothist_style.py,sha256=AwT7vCeeEcPm5RBnxWl-seRy4fpea8mz-_var0Ke6w8,12780
8
+ plothist/plotters.py,sha256=H6dqjJRkX5G3hH0005fiYh-d2G74pGuhuX82TJquyJo,43841
9
+ plothist/variable_registry.py,sha256=wQ-a-enGfdw2Z1PCiQBA7V2nY3nk75lHFAocQY-aZ5g,10157
10
+ plothist/scripts/__init__.py,sha256=a3gSwGAB4t_vPPweppJx_TsJKtuEuIk-jcO8sDxf6Ds,94
11
+ plothist/scripts/make_examples.py,sha256=mhk7tQUt43fcyZgL7Vq22GvqVXMTcmFae6QPBDAHBoY,7342
12
+ plothist-1.4.0.dist-info/METADATA,sha256=GP-LTKQ_yWyDVWaJaFpxlFg7si4C6l2Riy9279ZSkNc,4737
13
+ plothist-1.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ plothist-1.4.0.dist-info/entry_points.txt,sha256=XPdmI8l_6EHMQl_3J_N1AVNNDGCatSQn86bMs1iu8K0,88
15
+ plothist-1.4.0.dist-info/licenses/AUTHORS.md,sha256=02x3_8PNyTsXcRs0IlJeCTOmpGNRqymcJ71-2QtR37E,111
16
+ plothist-1.4.0.dist-info/licenses/LICENSE,sha256=bfaEdGehofQDaw-zDdVMHNUKo1FrOm6oGUEF-ltrp6w,1523
17
+ plothist-1.4.0.dist-info/RECORD,,