plothist 1.4.0__py3-none-any.whl → 1.6.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.
Files changed (66) hide show
  1. plothist/__init__.py +5 -5
  2. plothist/_version.py +2 -2
  3. plothist/comparison.py +170 -120
  4. plothist/examples/1d_hist/1d_comparison_asymmetry.py +37 -0
  5. plothist/examples/1d_hist/1d_comparison_difference.py +40 -0
  6. plothist/examples/1d_hist/1d_comparison_efficiency.py +37 -0
  7. plothist/examples/1d_hist/1d_comparison_only_efficiency.py +33 -0
  8. plothist/examples/1d_hist/1d_comparison_pull.py +37 -0
  9. plothist/examples/1d_hist/1d_comparison_ratio.py +37 -0
  10. plothist/examples/1d_hist/1d_comparison_relative_difference.py +37 -0
  11. plothist/examples/1d_hist/1d_comparison_split_ratio.py +37 -0
  12. plothist/examples/1d_hist/1d_elt1.py +38 -0
  13. plothist/examples/1d_hist/1d_elt1_stacked.py +45 -0
  14. plothist/examples/1d_hist/1d_elt2.py +33 -0
  15. plothist/examples/1d_hist/1d_hist_simple.py +28 -0
  16. plothist/examples/1d_hist/1d_int_category.py +41 -0
  17. plothist/examples/1d_hist/1d_profile.py +33 -0
  18. plothist/examples/1d_hist/1d_side_by_side.py +58 -0
  19. plothist/examples/1d_hist/1d_str_category.py +41 -0
  20. plothist/examples/1d_hist/README.rst +4 -0
  21. plothist/examples/2d_hist/2d_hist_correlations.py +65 -0
  22. plothist/examples/2d_hist/2d_hist_simple.py +28 -0
  23. plothist/examples/2d_hist/2d_hist_simple_discrete_colormap.py +42 -0
  24. plothist/examples/2d_hist/2d_hist_uneven.py +28 -0
  25. plothist/examples/2d_hist/2d_hist_with_projections.py +36 -0
  26. plothist/examples/2d_hist/README.rst +4 -0
  27. plothist/examples/README.rst +7 -0
  28. plothist/examples/advanced/1d_comparison_advanced.py +87 -0
  29. plothist/examples/advanced/1d_side_by_side_with_numbers.py +81 -0
  30. plothist/examples/advanced/README.rst +4 -0
  31. plothist/examples/advanced/asymmetry_comparison_advanced.py +133 -0
  32. plothist/examples/advanced/model_examples_flatten2D.py +86 -0
  33. plothist/examples/func_1d/README.rst +4 -0
  34. plothist/examples/func_1d/fct_1d.py +27 -0
  35. plothist/examples/func_1d/fct_1d_stacked.py +42 -0
  36. plothist/examples/model_ex/README.rst +4 -0
  37. plothist/examples/model_ex/model_all_comparisons.py +103 -0
  38. plothist/examples/model_ex/model_all_comparisons_no_model_unc.py +115 -0
  39. plothist/examples/model_ex/model_examples_pull.py +56 -0
  40. plothist/examples/model_ex/model_examples_pull_no_model_unc.py +59 -0
  41. plothist/examples/model_ex/model_examples_stacked.py +74 -0
  42. plothist/examples/model_ex/model_examples_stacked_unstacked.py +60 -0
  43. plothist/examples/model_ex/model_examples_unstacked.py +57 -0
  44. plothist/examples/model_ex/model_with_stacked_and_unstacked_function_components.py +50 -0
  45. plothist/examples/model_ex/model_with_stacked_and_unstacked_histograms_components.py +69 -0
  46. plothist/examples/model_ex/ratio_data_vs_model_with_stacked_and_unstacked_function_components.py +61 -0
  47. plothist/examples/utility/README.rst +4 -0
  48. plothist/examples/utility/add_text_example.py +39 -0
  49. plothist/examples/utility/color_palette_hists.py +94 -0
  50. plothist/examples/utility/color_palette_squares.py +100 -0
  51. plothist/examples/utility/matplotlib_vs_plothist_style.py +63 -0
  52. plothist/examples/utility/uncertainty_types.py +120 -0
  53. plothist/histogramming.py +60 -39
  54. plothist/plothist_style.py +56 -59
  55. plothist/plotters.py +210 -195
  56. plothist/test_helpers.py +43 -0
  57. plothist/variable_registry.py +46 -30
  58. {plothist-1.4.0.dist-info → plothist-1.6.0.dist-info}/METADATA +1 -1
  59. plothist-1.6.0.dist-info/RECORD +64 -0
  60. plothist/scripts/__init__.py +0 -3
  61. plothist/scripts/make_examples.py +0 -209
  62. plothist-1.4.0.dist-info/RECORD +0 -17
  63. plothist-1.4.0.dist-info/entry_points.txt +0 -2
  64. {plothist-1.4.0.dist-info → plothist-1.6.0.dist-info}/WHEEL +0 -0
  65. {plothist-1.4.0.dist-info → plothist-1.6.0.dist-info}/licenses/AUTHORS.md +0 -0
  66. {plothist-1.4.0.dist-info → plothist-1.6.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,43 @@
1
+ from __future__ import annotations
2
+
3
+ import runpy
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ import matplotlib.figure
8
+
9
+
10
+ def run_script_and_get_object(script_path_str: str, name: str) -> Any | None:
11
+ """
12
+ Runs a Python script from a given file path, temporarily disables saving of matplotlib figures
13
+ to suppress file output, and retrieves a variable from the script's global namespace by name.
14
+ The retrieved variable can be of any type.
15
+
16
+ Typically used with name="fig" to get the figure object created in the script.
17
+
18
+ Parameters:
19
+ script_path_str (str): Path to the Python script file to execute.
20
+ name (str): Name of the variable in the script's global namespace to retrieve.
21
+
22
+ Returns:
23
+ Any or None: The specified variable from the script's global namespace if present;
24
+ otherwise, None.
25
+ """
26
+ script_path = Path(script_path_str).resolve()
27
+
28
+ if not script_path.is_file():
29
+ raise FileNotFoundError(f"Script file not found: {script_path_str}")
30
+
31
+ original_savefig = matplotlib.figure.Figure.savefig
32
+
33
+ def suppressed_savefig(*args, **kwargs):
34
+ pass
35
+
36
+ matplotlib.figure.Figure.savefig = suppressed_savefig
37
+
38
+ try:
39
+ globals_dict = runpy.run_path(str(script_path))
40
+ finally:
41
+ matplotlib.figure.Figure.savefig = original_savefig
42
+
43
+ return globals_dict.get(name)
@@ -13,7 +13,7 @@ import yaml
13
13
  from plothist.histogramming import create_axis
14
14
 
15
15
 
16
- def _check_if_variable_registry_exists(path):
16
+ def _check_if_variable_registry_exists(path: str) -> None:
17
17
  """
18
18
  Check if the variable registry file exists at the specified path.
19
19
 
@@ -32,16 +32,18 @@ def _check_if_variable_registry_exists(path):
32
32
  If the variable registry file does not exist.
33
33
  """
34
34
  if not os.path.exists(path) and path == "./variable_registry.yaml":
35
- raise RuntimeError("Did you forgot to run create_variable_registry()?")
35
+ raise RuntimeError("Did you forget to run create_variable_registry()?")
36
36
 
37
37
 
38
- def _save_variable_registry(variable_registry, path="./variable_registry.yaml"):
38
+ def _save_variable_registry(
39
+ variable_registry: dict[str, dict], path: str = "./variable_registry.yaml"
40
+ ) -> None:
39
41
  """
40
42
  Save the variable registry to a yaml file.
41
43
 
42
44
  Parameters
43
45
  ----------
44
- variable_registry : dict
46
+ variable_registry : dict[str, dict]
45
47
  The variable registry to save.
46
48
  path : str, optional
47
49
  The path to the variable registry file (default is "./variable_registry.yaml").
@@ -58,8 +60,11 @@ def _save_variable_registry(variable_registry, path="./variable_registry.yaml"):
58
60
 
59
61
 
60
62
  def create_variable_registry(
61
- variable_keys, path="./variable_registry.yaml", custom_dict=None, reset=False
62
- ):
63
+ variable_keys: list[str],
64
+ path: str = "./variable_registry.yaml",
65
+ custom_dict: dict | None = None,
66
+ reset: bool = False,
67
+ ) -> None:
63
68
  """
64
69
  Create the variable registry yaml file given a list of variable keys.
65
70
  It stores all the plotting information for each variable.
@@ -76,7 +81,7 @@ def create_variable_registry(
76
81
  variable name in data.
77
82
  bins : int
78
83
  Number of bins, default is 50.
79
- range: list of two float
84
+ range: tuple[float, float]
80
85
  Range of the variables, default is [min, max] of the data.
81
86
  label : str
82
87
  Label to display, default is variable name. Latex supported by surrounding the label with $label$.
@@ -93,7 +98,7 @@ def create_variable_registry(
93
98
 
94
99
  Parameters
95
100
  ----------
96
- variable_keys : list
101
+ variable_keys : list[str]
97
102
  A list of variable keys to be registered.
98
103
  path : str, optional
99
104
  The path to the variable registry file (default is "./variable_registry.yaml").
@@ -101,8 +106,6 @@ def create_variable_registry(
101
106
  A dictionary containing the plotting information for the variables. Default dictionary is the one described above.
102
107
  reset : bool, optional
103
108
  If True, the registry will be reset to default values for all variable keys (default is False).
104
-
105
-
106
109
  """
107
110
 
108
111
  if not os.path.exists(path):
@@ -124,7 +127,7 @@ def create_variable_registry(
124
127
  variable_key: {
125
128
  "name": variable_key,
126
129
  "bins": 50,
127
- "range": ["min", "max"],
130
+ "range": ("min", "max"),
128
131
  "label": variable_key,
129
132
  "log": False,
130
133
  "legend_location": "best",
@@ -137,7 +140,9 @@ def create_variable_registry(
137
140
  _save_variable_registry(variable_registry, path=path)
138
141
 
139
142
 
140
- def get_variable_from_registry(variable_key, path="./variable_registry.yaml"):
143
+ def get_variable_from_registry(
144
+ variable_key: str, path: str = "./variable_registry.yaml"
145
+ ) -> dict:
141
146
  """
142
147
  This function retrieves the parameter information for a variable from the variable registry file specified by the 'path' parameter.
143
148
  It loads the variable registry file and returns the dictionary entry corresponding to the specified variable name.
@@ -163,12 +168,21 @@ def get_variable_from_registry(variable_key, path="./variable_registry.yaml"):
163
168
 
164
169
  with open(path) as f:
165
170
  variable_registry = yaml.safe_load(f)
171
+ if "range" in variable_registry[variable_key] and isinstance(
172
+ variable_registry[variable_key]["range"], list
173
+ ):
174
+ variable_registry[variable_key]["range"] = tuple(
175
+ variable_registry[variable_key]["range"]
176
+ )
166
177
  return variable_registry[variable_key]
167
178
 
168
179
 
169
180
  def update_variable_registry(
170
- dictionary, variable_keys=None, path="./variable_registry.yaml", overwrite=False
171
- ):
181
+ dictionary: dict,
182
+ variable_keys: list[str] | None = None,
183
+ path: str = "./variable_registry.yaml",
184
+ overwrite: bool = False,
185
+ ) -> None:
172
186
  """
173
187
  Update the variable registry file with a dictionary. Each key in the provided dictionary will be added as parameters for each variable. If they are already in the variable information, they will be updated with the new values only if the overwrite flag is True.
174
188
 
@@ -176,12 +190,12 @@ def update_variable_registry(
176
190
  ----------
177
191
  dictionary : dict
178
192
  A dictionary containing the information to update the registry with.
179
- variable_keys : list
193
+ variable_keys : list[str]
180
194
  A list of variable keys for which to update the registry. Default is None: all variables in the registry are updated.
181
195
  path : str, optional
182
196
  The path to the variable registry file (default is "./variable_registry.yaml").
183
197
  overwrite : bool, optional
184
- If True, the keys will be overwrite by the provided value in the dictionary (default is False).
198
+ If True, the keys will be overwritten by the provided value in the dictionary (default is False).
185
199
 
186
200
  Returns
187
201
  -------
@@ -204,16 +218,18 @@ def update_variable_registry(
204
218
 
205
219
 
206
220
  def remove_variable_registry_parameters(
207
- parameters, variable_keys=None, path="./variable_registry.yaml"
208
- ):
221
+ parameters: list[str],
222
+ variable_keys: list[str] | None = None,
223
+ path: str = "./variable_registry.yaml",
224
+ ) -> None:
209
225
  """
210
226
  Remove the specified parameters from the variable registry file.
211
227
 
212
228
  Parameters
213
229
  ----------
214
- parameters : list
230
+ parameters : list[str]
215
231
  A list of parameters to remove from the variable keys.
216
- variable_keys : list
232
+ variable_keys : list[str]
217
233
  A list of variable keys for which to remove the specified parameters from the registry. Default is None: all variables in the registry are updated.
218
234
  path : str, optional
219
235
  The path to the variable registry file (default is "./variable_registry.yaml").
@@ -245,10 +261,10 @@ def remove_variable_registry_parameters(
245
261
 
246
262
  def update_variable_registry_ranges(
247
263
  data,
248
- variable_keys=None,
249
- path="./variable_registry.yaml",
250
- overwrite=False,
251
- ):
264
+ variable_keys: list[str] | None = None,
265
+ path: str = "./variable_registry.yaml",
266
+ overwrite: bool = False,
267
+ ) -> None:
252
268
  """
253
269
  Update the range parameters for multiple variables in the variable registry file.
254
270
 
@@ -256,12 +272,12 @@ def update_variable_registry_ranges(
256
272
  ----------
257
273
  data : numpy.ndarray or pandas.DataFrame
258
274
  A dataset containing the data for the variables.
259
- variable_keys : list
275
+ variable_keys : list[str]
260
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.
261
277
  path : str, optional
262
278
  The path to the variable registry file (default is "./variable_registry.yaml").
263
279
  overwrite : bool, optional
264
- If True, the range parameters will be overwrite even if it's not equal to ["min", "max"] (default is False).
280
+ If True, the range parameters will be overwritten even if it's not equal to ("min", "max") (default is False).
265
281
 
266
282
  Returns
267
283
  -------
@@ -286,13 +302,13 @@ def update_variable_registry_ranges(
286
302
  f"Variable {variable_key} does not have a name, bins or range property in the registry {path}."
287
303
  )
288
304
 
289
- range = ["min", "max"] if overwrite else variable["range"]
305
+ range = ("min", "max") if overwrite else variable["range"]
290
306
 
291
- if range == ["min", "max"]:
292
- axis = create_axis(variable["bins"], range, data[variable["name"]])
307
+ if tuple(range) == ("min", "max"):
308
+ axis = create_axis(variable["bins"], tuple(range), data[variable["name"]])
293
309
  if isinstance(axis, bh.axis.Regular):
294
310
  update_variable_registry(
295
- {"range": [float(axis.edges[0]), float(axis.edges[-1])]},
311
+ {"range": (float(axis.edges[0]), float(axis.edges[-1]))},
296
312
  [variable_key],
297
313
  path=path,
298
314
  overwrite=True,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: plothist
3
- Version: 1.4.0
3
+ Version: 1.6.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/
@@ -0,0 +1,64 @@
1
+ plothist/__init__.py,sha256=ikcYOZqMs4WKAJ2rM-3BnHu_CQxLlQCuc-iFo_a-Mns,2760
2
+ plothist/_version.py,sha256=5FGJNp9Lkk9uOxeCjXpoCGBF79Ar6LGPOR7-atBqb_4,511
3
+ plothist/_version.pyi,sha256=o7uNL6MhuJoiqpEnriU7rBT6TmkJZA-i2qMoNz9YcgQ,82
4
+ plothist/comparison.py,sha256=jkONOiCp8RNBk8V_VvwACdfJJqo89rK9NQW71XxJscc,19623
5
+ plothist/default_style.mplstyle,sha256=7MmB2uiXmD_DSqFHeH1xxC-lTctBD_EASxMdSOsPep0,1574
6
+ plothist/histogramming.py,sha256=o0RLdoEhxHA7Ws0bvK3DewsbQEu-QOtJNw5Md5AckHM,11474
7
+ plothist/plothist_style.py,sha256=bbYFc-qsrTfdbacCBAAzmiHJoRIh3toBomFfxtTRNMs,13255
8
+ plothist/plotters.py,sha256=ncPZa34Fo1mbFxv0guFc2zEciX_JXGKJxeIfcUDaP6w,46336
9
+ plothist/test_helpers.py,sha256=JXhxUdqMszkawxkU8cDPqipkSXNHfsKSfe3K-4frDrM,1379
10
+ plothist/variable_registry.py,sha256=usVLoDLbIMzjeRDazIH0OIjQIUsh9RSJ9Ncnhn1V9qw,10783
11
+ plothist/examples/README.rst,sha256=PVzkOQzVnNeWORxEv3NNv5XoSN2Y71D7SYzRkCqirfA,151
12
+ plothist/examples/1d_hist/1d_comparison_asymmetry.py,sha256=Rp9gv6E5z9KgIhnraS9AjGSMgHLhSHd_u5L-vG0w-gU,757
13
+ plothist/examples/1d_hist/1d_comparison_difference.py,sha256=FMKoTjMIQp6VsFXspVBy2AdxHPDnxhMfj9PCvE4qVjk,877
14
+ plothist/examples/1d_hist/1d_comparison_efficiency.py,sha256=qYf8a5-IGN-n6T_EIcyyoytgmefi3k3FjxNh3oPNE1M,851
15
+ plothist/examples/1d_hist/1d_comparison_only_efficiency.py,sha256=fjCfBfOl7exbtQGVvGXwAv7pQC_t_NEG7mebjobQiDs,687
16
+ plothist/examples/1d_hist/1d_comparison_pull.py,sha256=JC9Mxy1nQcLwcgogxjp3NSsoeORrvQ51ESmFWwhsIZQ,689
17
+ plothist/examples/1d_hist/1d_comparison_ratio.py,sha256=G7jmSenqNBtFxLSizwjNtqzjw3zqlEmp4vccbFfOfRE,685
18
+ plothist/examples/1d_hist/1d_comparison_relative_difference.py,sha256=APS8Zgb-xBLcQcJcfGatAU50pyB1iywlWsly3l1-prk,793
19
+ plothist/examples/1d_hist/1d_comparison_split_ratio.py,sha256=l5f-N7Bn6pL5xt3ZpHWfAXHMmOEK_DZBKVll_ALZYnY,771
20
+ plothist/examples/1d_hist/1d_elt1.py,sha256=ArSpYSlaTi6jqYL2Od9CQxFqqSkgFFoogqBXN0OcL6c,784
21
+ plothist/examples/1d_hist/1d_elt1_stacked.py,sha256=bogh66gUdf14xYv9Z9cs7WBNp_7HJbdcgSTVknckHXM,786
22
+ plothist/examples/1d_hist/1d_elt2.py,sha256=OJDMsf4H_fJuB_wXbTb04DCGP1cftpmBl-0Fw_EphwA,597
23
+ plothist/examples/1d_hist/1d_hist_simple.py,sha256=bDe1q1h1dnY_Cx5A4TvoYInR8DHb9JBosdOwG2Z56uk,412
24
+ plothist/examples/1d_hist/1d_int_category.py,sha256=mb4Eq3Of_vPJVMPPwYYDzT5gwrwpboexpjJU8gt1d8o,881
25
+ plothist/examples/1d_hist/1d_profile.py,sha256=otmerm64DNAYnRWaablQkQDgUVOvjLNDc6WhdghgZm8,685
26
+ plothist/examples/1d_hist/1d_side_by_side.py,sha256=sAHhBVnopINQscFaUpVI4KNs18e_1laHyrYBOlmU_fQ,1557
27
+ plothist/examples/1d_hist/1d_str_category.py,sha256=2DtxfNMAlcZ6pYx44lP0-sgY4M73-R0aBH61uEJmKA0,880
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
30
+ plothist/examples/2d_hist/2d_hist_simple.py,sha256=1n5yqOJxHzD31njOk85dTjuXhkogCDIS4-EG63XcnQ0,521
31
+ plothist/examples/2d_hist/2d_hist_simple_discrete_colormap.py,sha256=E1zeMIDP25R_ppkB-wDz7TxaLsxf7dCs87FrPTPWTAc,1000
32
+ plothist/examples/2d_hist/2d_hist_uneven.py,sha256=kR53XrSx38efG1wHEI69BIcPKVQzJygkr7ax_CFzBIA,646
33
+ plothist/examples/2d_hist/2d_hist_with_projections.py,sha256=EPGNoXQu7Oa0xS_fDc21_0dCVPLeKpSyv3dylfwXIDs,725
34
+ plothist/examples/2d_hist/README.rst,sha256=SCD39UgHb8vat63gNkOlDWPjwZj9INUS516D5DxW0Vk,116
35
+ plothist/examples/advanced/1d_comparison_advanced.py,sha256=RHWejmv8OQcgZ2R9yfAehv8cc8vQ5qr5gcVApGWdQhI,2668
36
+ plothist/examples/advanced/1d_side_by_side_with_numbers.py,sha256=46k1RXFPQ9x2yfeWQdAh5sz4I9C0SnYtQgqeL29_oQY,2437
37
+ plothist/examples/advanced/README.rst,sha256=ulygCIs7LUaViLpeTCIG2qcG9FEohccrlR2nXYLnkO4,112
38
+ plothist/examples/advanced/asymmetry_comparison_advanced.py,sha256=fteFmenSzhhZxgz4OU3fL8ejZKGnGpbNz-Zmt4M6g2c,2670
39
+ plothist/examples/advanced/model_examples_flatten2D.py,sha256=b4Rl6ItrsaddVL5uC9Gr3ccgSyhjW1RAtxSQgcCs_JA,2233
40
+ plothist/examples/func_1d/README.rst,sha256=tez3Jpva9yv7T7bDfXE9dCdmThJ1ALZRiEHOfFkrCNk,108
41
+ plothist/examples/func_1d/fct_1d.py,sha256=DRbKnImIqVYVXqH79X54YnxyGLu914fEmxry3fLBDsM,455
42
+ plothist/examples/func_1d/fct_1d_stacked.py,sha256=2PzLk3Os5firowyaEFoJrCrTewuRhQ2gXp7dTtKEFVM,655
43
+ plothist/examples/model_ex/README.rst,sha256=EDOiF2e_YeTg9I57yLmaGwzN0ZiO5c7n4bIWgqznKe0,103
44
+ plothist/examples/model_ex/model_all_comparisons.py,sha256=2DcF8axBgwD8lC4DkytWnNlFNsiEs7CuiP-9zxcPEV4,2555
45
+ plothist/examples/model_ex/model_all_comparisons_no_model_unc.py,sha256=xj1ByCadvlES2lYGfQkfYAcQSEGTSuWUBg6OGs8AN4s,3163
46
+ plothist/examples/model_ex/model_examples_pull.py,sha256=yesH6fYp5PfbfoHifRKt9EKo1AdrC0_cTAaSfRvUbgI,1462
47
+ plothist/examples/model_ex/model_examples_pull_no_model_unc.py,sha256=FXt25ObeeC3hdshpLTE6Bc-A1wAvIHPBUmIMPvC0g9k,1687
48
+ plothist/examples/model_ex/model_examples_stacked.py,sha256=cXuIwf1sNGiJ_XWj-yNIxFNzJ_5amnNUB7TYKvBcPVo,1994
49
+ plothist/examples/model_ex/model_examples_stacked_unstacked.py,sha256=geL-d997z7FyCLsDS6gGfkrGlGczLCv11QGhgvsH-U4,1792
50
+ plothist/examples/model_ex/model_examples_unstacked.py,sha256=jqwzfZLn2-I88NZ7BTaKjdNTdekP1i-jQXBPICyoPPA,1574
51
+ plothist/examples/model_ex/model_with_stacked_and_unstacked_function_components.py,sha256=KlISHHH3ASn4WS64yJ1ifdJIZX0RLBRUPUBJ5dEqvAM,1221
52
+ plothist/examples/model_ex/model_with_stacked_and_unstacked_histograms_components.py,sha256=fR7q5vDKG66-nAtjAiHFwQ2D10s-8GTK6IJ2HKtFFoQ,1966
53
+ plothist/examples/model_ex/ratio_data_vs_model_with_stacked_and_unstacked_function_components.py,sha256=HSrIs6XCiGgQCaMG9iG9vWe2491hb5hOoYyzJvrJL2Q,1367
54
+ plothist/examples/utility/README.rst,sha256=8qQeSXjzdPDlp58cbaHnAq5O55BSp8V-Umr9wmouwJ8,77
55
+ plothist/examples/utility/add_text_example.py,sha256=EB7ZUStt2E8GawjWNmVbSV34NINZ8v-4-rQBw1_gFD4,811
56
+ plothist/examples/utility/color_palette_hists.py,sha256=uIc6TrmjTj8EUif1Yj1wq4nXoY1sgJpS15yPe3-FpTw,2383
57
+ plothist/examples/utility/color_palette_squares.py,sha256=pNasgvZZApu-sCqhi5FTJAH3l6Px2cgB5RwJcQ1eF1U,2689
58
+ plothist/examples/utility/matplotlib_vs_plothist_style.py,sha256=iEIfbFKmAN-PcDCzw_sBuhrfpes4I2wUVfC0r1vUHEw,2006
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,,
@@ -1,3 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from .make_examples import make_examples as make_examples
@@ -1,209 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import hashlib
4
- import os
5
- import subprocess
6
- import warnings
7
- from importlib import resources
8
-
9
- import yaml
10
- from packaging import version
11
-
12
- import plothist
13
-
14
- _matplotlib_version = "3.10.0"
15
- _numpy_version = "2.0.0"
16
-
17
-
18
- def make_examples(no_input=False, check_svg=False, print_code=False):
19
- """
20
- This function can redo automatically all the examples from the documentation. Only works with python 3.9 or higher.
21
-
22
- Parameters
23
- ----------
24
- no_input : bool, optional
25
- If True, the function will not ask for any input and will relaunch all the python files.
26
- check_svg : bool, optional
27
- If True, the function will check that the svg files have not changed after the relaunch.
28
- print_code : bool, optional
29
- If True, the function will print the code that will be executed for each python file.
30
-
31
- Raises
32
- ------
33
- FileNotFoundError
34
- If the example or img folder does not exist, the function will raise a FileNotFoundError.
35
- """
36
-
37
- import matplotlib
38
-
39
- if version.parse(matplotlib.__version__) < version.parse(_matplotlib_version):
40
- warnings.warn(
41
- f"svg behavior is not consistent across matplotlib versions. Please run this script with matplotlib {_matplotlib_version} or higher. Skipping.",
42
- stacklevel=2,
43
- )
44
- return 1
45
-
46
- import numpy
47
-
48
- if version.parse(numpy.__version__) < version.parse(_numpy_version):
49
- warnings.warn(
50
- f"svg behavior is not consistent across numpy versions. Please run this script with numpy {_numpy_version} or higher. Skipping.",
51
- stacklevel=2,
52
- )
53
- return 1
54
-
55
- plothist_folder = (
56
- plothist.__path__[0]
57
- if os.environ.get("PLOTHIST_PATH") is None
58
- else os.environ.get("PLOTHIST_PATH")
59
- )
60
-
61
- example_folder = plothist_folder + "/../../docs/examples"
62
- img_folder = plothist_folder + "/../../docs/img"
63
-
64
- if not os.path.exists(example_folder) or not os.path.exists(img_folder):
65
- raise FileNotFoundError(
66
- f"Could not find the example {example_folder} or img {img_folder} folder for the documentation.\nTry to run `export PLOTHIST_PATH=path/to/plothist` before launching the script."
67
- )
68
-
69
- temp_img_folder = plothist_folder + "/../../docs/temp_img"
70
-
71
- # Get all python files in the example folder
72
- python_files = [
73
- file
74
- for root, dirs, files in os.walk(example_folder)
75
- for file in files
76
- if file.endswith(".py")
77
- ]
78
- python_files.sort()
79
-
80
- if no_input:
81
- k_plots = "all"
82
- else:
83
- # Ask which python files to relaunch
84
- print(
85
- "Which python script do you want to relauch? (ex: 1 2 4 ... [OR] 1d model 2d color [OR] all (just press enter for all))"
86
- )
87
- for k_python, python_file in enumerate(python_files):
88
- print(f"\t{f'{k_python}':<3} - {python_file}")
89
- k_plots = input("> ")
90
-
91
- if k_plots == "":
92
- k_plots = "all"
93
-
94
- # Get the list of python files to relaunch
95
- plots_to_redo = []
96
- for k_plot in k_plots.split(" "):
97
- if k_plot == "all":
98
- plots_to_redo = python_files[:]
99
- break
100
- if k_plot in ["1d", "2d", "model", "color"]:
101
- plots_to_redo.extend(
102
- [
103
- python_file
104
- for python_file in python_files
105
- if python_file.startswith(k_plot)
106
- ]
107
- )
108
- else:
109
- plots_to_redo.append(python_files[int(k_plot)])
110
-
111
- # Temp image folder
112
- if not os.path.exists(temp_img_folder):
113
- os.makedirs(temp_img_folder, exist_ok=True)
114
-
115
- # Get the metadata for the svg files
116
- metadata_file = (
117
- resources.files("plothist_utils") / "metadata" / ".svg_metadata.yaml"
118
- )
119
- with open(metadata_file) as f:
120
- svg_metadata = yaml.safe_load(f)
121
-
122
- svg_metadata = "metadata=" + str(svg_metadata)
123
-
124
- if check_svg:
125
- from pytest import fail
126
-
127
- img_hashes = {}
128
- for file in os.listdir(img_folder):
129
- if file.endswith(".svg"):
130
- with open(os.path.join(img_folder, file)) as f:
131
- img_hashes[file] = hashlib.sha256(f.read().encode()).hexdigest()
132
-
133
- # Iterate through all subfolders and files in the source folder
134
- for root, _dirs, files in os.walk(example_folder):
135
- for file in files:
136
- if file not in plots_to_redo:
137
- continue
138
-
139
- print(f"Redoing {file}")
140
- file_path = os.path.join(root, file)
141
- file_code = ""
142
-
143
- with open(file_path) as f:
144
- for line in f:
145
- if "savefig" in line:
146
- if file == "matplotlib_vs_plothist_style.py":
147
- line = (
148
- " plt.rcParams['svg.hashsalt'] = '8311311'\n" + line
149
- )
150
- line = line.replace(
151
- "savefig(",
152
- f"savefig({svg_metadata}, fname=",
153
- )
154
- file_code += line
155
-
156
- if print_code:
157
- print("\n" * 10 + file_code)
158
-
159
- result = subprocess.run(
160
- ["python", "-c", file_code],
161
- cwd=temp_img_folder,
162
- capture_output=True,
163
- text=True,
164
- check=False,
165
- )
166
- if result.returncode != 0 and check_svg:
167
- fail(f"Error while redoing {file}:\n{result.stderr}\n{result.stdout}")
168
- elif result.returncode != 0:
169
- print(f"Error while redoing {file}:\n{result.stderr}\n{result.stdout}")
170
-
171
- # Move the svg files to the img folder
172
- for file in os.listdir(temp_img_folder):
173
- if file.endswith(".svg"):
174
- subprocess.run(
175
- ["mv", os.path.join(temp_img_folder, file), img_folder], check=False
176
- )
177
-
178
- # Remove the temp folder
179
- subprocess.run(["rm", "-rf", temp_img_folder], check=False)
180
-
181
- # Check that the svg files have not changed
182
- if check_svg:
183
- new_img_hashes = {}
184
- for file in os.listdir(img_folder):
185
- if file.endswith(".svg"):
186
- with open(os.path.join(img_folder, file)) as f:
187
- new_img_hashes[file] = hashlib.sha256(f.read().encode()).hexdigest()
188
-
189
- # Check that the hashes are the same and print the ones that are different
190
- changed_img = []
191
- for file, file_hash in img_hashes.items():
192
- if new_img_hashes[file] != file_hash:
193
- changed_img.append(file)
194
- if changed_img:
195
- changed_img.sort()
196
- fail(
197
- f"The following images in the doc have changed [{len(changed_img)} out of {len(img_hashes)}]:\n{', '.join(changed_img)}.\nPlease run `plothist_make_examples`, check the new images and commit them if they are correct."
198
- )
199
- if len(new_img_hashes) != len(img_hashes):
200
- fail(
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())}"
202
- )
203
- return None
204
- return None
205
- return None
206
-
207
-
208
- if __name__ == "__main__":
209
- make_examples()
@@ -1,17 +0,0 @@
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,,
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- plothist_make_examples = plothist.scripts.make_examples:make_examples