py-pluto 1.1.4__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 (73) hide show
  1. pyPLUTO/__init__.py +22 -0
  2. pyPLUTO/amr.py +745 -0
  3. pyPLUTO/baseloadmixin.py +258 -0
  4. pyPLUTO/baseloadstate.py +45 -0
  5. pyPLUTO/codes/echo_load.py +161 -0
  6. pyPLUTO/configure.py +261 -0
  7. pyPLUTO/gui/config.py +174 -0
  8. pyPLUTO/gui/custom_var.py +435 -0
  9. pyPLUTO/gui/globals.py +108 -0
  10. pyPLUTO/gui/main.py +17 -0
  11. pyPLUTO/gui/main_window.py +177 -0
  12. pyPLUTO/gui/panels.py +66 -0
  13. pyPLUTO/gui/utils.py +273 -0
  14. pyPLUTO/h_pypluto.py +84 -0
  15. pyPLUTO/image.py +302 -0
  16. pyPLUTO/imagefuncs/colorbar.py +240 -0
  17. pyPLUTO/imagefuncs/contour.py +254 -0
  18. pyPLUTO/imagefuncs/create_axes.py +464 -0
  19. pyPLUTO/imagefuncs/display.py +306 -0
  20. pyPLUTO/imagefuncs/figure.py +395 -0
  21. pyPLUTO/imagefuncs/imagetools.py +487 -0
  22. pyPLUTO/imagefuncs/interactive.py +403 -0
  23. pyPLUTO/imagefuncs/legend.py +250 -0
  24. pyPLUTO/imagefuncs/plot.py +311 -0
  25. pyPLUTO/imagefuncs/range.py +242 -0
  26. pyPLUTO/imagefuncs/scatter.py +270 -0
  27. pyPLUTO/imagefuncs/set_axis.py +497 -0
  28. pyPLUTO/imagefuncs/streamplot.py +297 -0
  29. pyPLUTO/imagefuncs/zoom.py +428 -0
  30. pyPLUTO/imagemixin.py +259 -0
  31. pyPLUTO/imagestate.py +45 -0
  32. pyPLUTO/load.py +447 -0
  33. pyPLUTO/loadfuncs/baseloadtools.py +71 -0
  34. pyPLUTO/loadfuncs/codeselection.py +48 -0
  35. pyPLUTO/loadfuncs/defpluto.py +123 -0
  36. pyPLUTO/loadfuncs/descriptor.py +102 -0
  37. pyPLUTO/loadfuncs/findfiles.py +182 -0
  38. pyPLUTO/loadfuncs/findformat.py +245 -0
  39. pyPLUTO/loadfuncs/initload.py +203 -0
  40. pyPLUTO/loadfuncs/loadvars.py +227 -0
  41. pyPLUTO/loadfuncs/offsetdata.py +87 -0
  42. pyPLUTO/loadfuncs/offsetfluid.py +408 -0
  43. pyPLUTO/loadfuncs/read_files.py +213 -0
  44. pyPLUTO/loadfuncs/readdata.py +619 -0
  45. pyPLUTO/loadfuncs/readdata_old.py +567 -0
  46. pyPLUTO/loadfuncs/readdefplini.py +101 -0
  47. pyPLUTO/loadfuncs/readfluid.py +479 -0
  48. pyPLUTO/loadfuncs/readformat.py +277 -0
  49. pyPLUTO/loadfuncs/readgridalone.py +224 -0
  50. pyPLUTO/loadfuncs/readgridfile.py +255 -0
  51. pyPLUTO/loadfuncs/readgridout.py +451 -0
  52. pyPLUTO/loadfuncs/readpart.py +419 -0
  53. pyPLUTO/loadfuncs/readtab.py +105 -0
  54. pyPLUTO/loadfuncs/write_files.py +283 -0
  55. pyPLUTO/loadmixin.py +419 -0
  56. pyPLUTO/loadpart.py +233 -0
  57. pyPLUTO/loadstate.py +68 -0
  58. pyPLUTO/newload.py +81 -0
  59. pyPLUTO/pytools.py +145 -0
  60. pyPLUTO/toolfuncs/findlines.py +551 -0
  61. pyPLUTO/toolfuncs/fourier.py +149 -0
  62. pyPLUTO/toolfuncs/nabla.py +676 -0
  63. pyPLUTO/toolfuncs/parttools.py +152 -0
  64. pyPLUTO/toolfuncs/transform.py +638 -0
  65. pyPLUTO/utils/annotator.py +27 -0
  66. pyPLUTO/utils/inspector.py +145 -0
  67. pyPLUTO/utils/make_docstrings.py +3 -0
  68. py_pluto-1.1.4.dist-info/METADATA +218 -0
  69. py_pluto-1.1.4.dist-info/RECORD +73 -0
  70. py_pluto-1.1.4.dist-info/WHEEL +5 -0
  71. py_pluto-1.1.4.dist-info/entry_points.txt +2 -0
  72. py_pluto-1.1.4.dist-info/licenses/LICENSE +27 -0
  73. py_pluto-1.1.4.dist-info/top_level.txt +1 -0
@@ -0,0 +1,311 @@
1
+ """PlotManager class."""
2
+
3
+ from typing import Any
4
+
5
+ import numpy as np
6
+ from numpy.typing import ArrayLike
7
+
8
+ from pyPLUTO.imagefuncs.imagetools import ImageToolsManager
9
+ from pyPLUTO.imagefuncs.legend import LegendManager
10
+ from pyPLUTO.imagefuncs.range import RangeManager
11
+ from pyPLUTO.imagefuncs.set_axis import AxisManager
12
+ from pyPLUTO.imagemixin import ImageMixin
13
+ from pyPLUTO.imagestate import ImageState
14
+ from pyPLUTO.utils.inspector import track_kwargs
15
+
16
+
17
+ class PlotManager(ImageMixin):
18
+ """PlotManager class.
19
+
20
+ It provides methods to create and manage plots in the
21
+ image. It is designed to work with the Image class and allows for dynamic
22
+ creation of plots based on the current state of the image. The class uses
23
+ the AxisManager, ImageToolsManager, LegendManager, and RangeManager to
24
+ handle the display and plotting of the images, axes, legends, and ranges,
25
+ respectively.
26
+ """
27
+
28
+ def __init__(self, state: ImageState) -> None:
29
+ """Initialize the PlotManager with the given state."""
30
+ self.state = state
31
+ self.AxisManager = AxisManager(state)
32
+ self.ImageToolsManager = ImageToolsManager(state)
33
+ self.LegendManager = LegendManager(state)
34
+ self.RangeManager = RangeManager(state)
35
+
36
+ @track_kwargs
37
+ def plot(
38
+ self,
39
+ x: ArrayLike | list[float],
40
+ y: ArrayLike | list[float] | None = None,
41
+ check: bool = True,
42
+ **kwargs: Any,
43
+ ) -> None:
44
+ """Creation of a 1D function plot (or a 1D slice plot).
45
+
46
+ This function plots a 1D function or a 1D slice. It creates a
47
+ simple figure and a single axis if none are given prior. If a single
48
+ function argument is given, it plots the graph of that function using
49
+ a linear variable as x parameter. However, if a pair of arrays is
50
+ provided, it plots the second as a function of the first one.
51
+
52
+ Returns
53
+ -------
54
+ - None
55
+
56
+ Parameters
57
+ ----------
58
+ - alpha: float, default 1.0
59
+ Sets the opacity of the plot, where 1.0 means total opaque and 0.0
60
+ means total transparent.
61
+ - aspect: 'auto' | 'equal' | float, default 'auto'
62
+ Sets the aspect ratio of the plot.
63
+ The 'auto' keyword is the default option (most likely the plot will
64
+ be squared). The 'equal' keyword will set the same scaling for x and
65
+ y. A float will fix the ratio between the y-scale and the x-scale
66
+ (1.0 is the same as 'equal').
67
+ - ax: ax | int | None, default None
68
+ The axis where to plot the lines. If None, a new axis is created or
69
+ the last axis is selected.
70
+ - bottom: float, default 0.1
71
+ The space from the bottom border to the last row of plots.
72
+ - c: str, default self.color
73
+ Determines the line color. If not defined, the program will loop
74
+ over an array of 10 color which are different for the most common
75
+ vision deficiencies.
76
+ - figsize: [float, float], default [8,5]
77
+ Sets the figure size. The default value is computed from the number
78
+ of rows and columns.
79
+ - fillstyle: {'full', 'left', 'right', 'bottom', 'top', 'none'},
80
+ default 'full'
81
+ Sets the marker filling. The default value is the fully filled
82
+ marker ('full').
83
+ - fontsize: float, default 17.0
84
+ Sets the fontsize for all the axes.
85
+ - grid: bool, default False
86
+ If enabled, creates a grid on the plot.
87
+ - label: str, default None
88
+ Associates a label to each line. Such labels will be used for the
89
+ creation of the legend.
90
+ - labelsize: float, default fontsize
91
+ Sets the labels fontþsize (which is the same for both labels).
92
+ The default value corresponds to the value of the keyword
93
+ 'fontsize'.
94
+ - legalpha: float, default 0.8
95
+ Sets the opacity of the legend.
96
+ - left: float, default 0.125
97
+ The space from the left border to the leftmost column of plots.
98
+ - legcols: int, default 1
99
+ Sets the number of columns that the legend should have.
100
+ - legpad: float, default 0.8
101
+ Sets the space between the lines (or symbols) and the correspondibg
102
+ text in the legend.
103
+ - legpos: int | str, default None
104
+ If enabled, creates a legend. This keyword selects the legend
105
+ location.
106
+ - legsize: float, default fontsize
107
+ Sets the fontsize of the legend. The default value is the default
108
+ fontsize value.
109
+ - legspace: float, default 2
110
+ Sets the space between the legend columns, in font-size units.
111
+ - ls: {'-', '--', '-.', ':', ' ', ect.}, default '-'
112
+ Sets the linestyle. The choices available are the ones defined in
113
+ the matplotlib package. Here are reported the most common ones.
114
+ - lw: float, default 1.3
115
+ Sets the linewidth of each line.
116
+ - marker: {'o', 'v', '^', '<', '>', 'X', ' ', etc.}, default ' '
117
+ Sets an optional symbol for every point. The default value is no
118
+ marker (' ').
119
+ - minorticks: str, default None
120
+ If not None enables the minor ticks on the plot (for both grid
121
+ axes).
122
+ - ms: float, default 3
123
+ Sets the marker size.
124
+ - mscale: fload, default 1.0
125
+ Sets the marker size scale in the legend.
126
+ - proj: str, default None
127
+ Custom projection for the plot (e.g. 3D). Recommended only if
128
+ needed. This keyword should be used only if the axis is created.
129
+ WARNING: pyPLUTO does not support 3D plotting for now, only 3D axes.
130
+ The 3D plot feature will be available in future releases.
131
+ - right: float, default 0.9
132
+ The space from the right border to the rightmost column of plots.
133
+ - ticksdir: {'in', 'out'}, default 'in'
134
+ Sets the ticks direction. The default option is 'in'.
135
+ - tickssize: float, default fontsize
136
+ Sets the ticks fontsize (which is the same for both grid axes).
137
+ The default value corresponds to the value of the keyword
138
+ 'fontsize'.
139
+ - title: str, default None
140
+ Places the title of the plot on top of it.
141
+ - titlesize: float, default fontsize
142
+ Sets the title fontsize. The default value corresponds to the value
143
+ of the keyword 'fontsize'.
144
+ - top: float, default 0.9
145
+ The space from the top border to the first row of plots.
146
+ - x (not optional): 1D array
147
+ This is the x-axis variable. If y is not defined, then this becomes
148
+ the y-axis variable.
149
+ - xrange: [float, float], default 'Default'
150
+ Sets the range in the x-direction. If not defined or set to
151
+ 'Default', the code will compute the range while plotting the data
152
+ by taking the minimum and the maximum values of the x-array. In case
153
+ of multiple lines, the code will also adapt to the previous ranges.
154
+ - xscale: {'linear','log'}, default 'linear'
155
+ If enabled (and different from default), sets automatically the
156
+ scale on the x-axis. Data in log scale should be used with the
157
+ keyword 'log', while data in linear scale should be used with the
158
+ keyword 'linear'.
159
+ - xticks: [float] | None | bool, default True
160
+ If enabled (and different from True), sets manually ticks on
161
+ x-axis. In order to completely remove the ticks the keyword should
162
+ be used with None.
163
+ - xtickslabels: [str] | None | bool, default True
164
+ If enabled (and different from True), sets manually the ticks
165
+ labels on the x-axis. In order to completely remove the ticks the
166
+ keyword should be used with None. Note that fixed tickslabels should
167
+ always correspond to fixed ticks.
168
+ - xtitle: str, default None
169
+ Sets and places the label of the x-axis.
170
+ - y: 1D array, default [None]
171
+ The y-axis variable.
172
+ - yrange: [float, float], default 'Default'
173
+ Sets the range in the y-direction. If not defined or set to
174
+ 'Default' the code will compute the range while plotting the data by
175
+ taking the minimum and the maximum values of the y-array. In case of
176
+ multiple lines, the code will also adapt to the previous ranges. It
177
+ also adds a small offset.
178
+ - yscale: {'linear','log'}, default 'linear'
179
+ If enabled (and different from True), sets automatically the scale
180
+ on the y-axis. Data in log scale should be used with the keyword
181
+ 'log', while data in linear scale should be used with the keyword
182
+ 'linear'.
183
+ - yticks: [float] | None | bool, default True
184
+ If enabled (and different from True), sets manually ticks on
185
+ y-axis. In order to completely remove the ticks the keyword should
186
+ be used with None.
187
+ - ytickslabels: [str] | None | bool, default True
188
+ If enabled (and different from True), sets manually the ticks
189
+ labels on the y-axis. In order to completely remove the ticks the
190
+ keyword should be used with None. Note that fixed tickslabels should
191
+ always correspond to fixed ticks.
192
+ - ytitle: str, default None
193
+ Sets and places the label of the y-axis.
194
+
195
+ ----
196
+
197
+ Examples
198
+ --------
199
+ - Example #1: create a simple plot of y as function of x
200
+
201
+ >>> import pyPLUTO as pp
202
+ >>> I = pp.Image()
203
+ >>> I.plot(x, y)
204
+
205
+ - Example #2: create a plot of y as function of x with custom range of
206
+ the axes and titles
207
+
208
+ >>> import pyPLUTO as pp
209
+ >>> I = pp.Image()
210
+ >>> I.plot(x, y, xrange = [0,100], yrange = [0.0,1.0],
211
+ title = 'y in function of x', xtitle = 'x', ytitle = 'y')
212
+
213
+ - Example #3: create a plot with logarithmic scale on y-axis
214
+
215
+ >>> import pyPLUTO as pp
216
+ >>> I = pp.Image()
217
+ >>> I.plot(x, y, yscale="log")
218
+
219
+ - Example #4: create a plot with a legend and custom ticks on x-axis
220
+
221
+ >>> import pyPLUTO as pp
222
+ >>> I = pp.Image()
223
+ >>> I.plot(x, y, label = 'y', legpos = 'lower right',
224
+ xticks = [0.2,0.4,0.6,0.8])
225
+
226
+ - Example #5: create plots on already existing axes
227
+
228
+ >>> import pypLUTO as pp
229
+ >>> I = pp.Image()
230
+ >>> I.create_axes(ncol=2)
231
+ >>> I.plot(x, y, ax=I.ax[0])
232
+ >>> I.plot(x, y * y, ax=I.ax[1])
233
+ >>> I.plot(x, z, ax=I.ax[0])
234
+
235
+ """
236
+ # Check parameters
237
+ kwargs.pop("check", check)
238
+
239
+ # If only one argument is given, it is the y-axis
240
+ if y is None:
241
+ y = np.asarray(x, dtype=float)
242
+ x = np.arange(y.size, dtype=float)
243
+ else:
244
+ # Convert x and y in numpy arrays
245
+ x = np.asarray(x, dtype=float)
246
+ y = np.asarray(y, dtype=float)
247
+
248
+ if self.fig is None:
249
+ raise ValueError(
250
+ "No figure is present. Please create a figure first."
251
+ )
252
+
253
+ # Set or create figure and axes
254
+ ax, nax = self.ImageToolsManager.assign_ax(
255
+ kwargs.pop("ax", None), **kwargs
256
+ )
257
+
258
+ # Set ax parameters
259
+ self.AxisManager.set_axis(ax=ax, check=False, **kwargs)
260
+ self.ImageToolsManager.hide_text(nax, ax.texts)
261
+
262
+ # Keyword xrange and yrange
263
+ self.RangeManager.set_xrange(
264
+ ax,
265
+ nax,
266
+ [np.nanmin(x), np.nanmax(x)],
267
+ self.setax[nax],
268
+ )
269
+ self.RangeManager.set_yrange(
270
+ ax,
271
+ nax,
272
+ [np.nanmin(y), np.nanmax(y)],
273
+ self.setay[nax],
274
+ data=(x.astype(np.float64), y),
275
+ # x=x.astype(np.float64),
276
+ # y=y,
277
+ )
278
+
279
+ # Set color line and increase the number of lines (if default color)
280
+ col_line = kwargs.get(
281
+ "c", self.color[self.nline[nax] % len(self.color)]
282
+ )
283
+ if not kwargs.get("c"):
284
+ self.nline[nax] = self.nline[nax] + 1
285
+
286
+ # Start plotting procedure
287
+ ax.plot(
288
+ x,
289
+ y,
290
+ c=col_line,
291
+ ls=kwargs.get("ls", "-"),
292
+ lw=kwargs.get("lw", 1.3),
293
+ marker=kwargs.get("marker", ""),
294
+ ms=kwargs.get("ms", 3.0),
295
+ label=kwargs.get("label", ""),
296
+ fillstyle=kwargs.get("fillstyle", "full"),
297
+ )
298
+
299
+ # Creation of the legend
300
+ self.legpos[nax] = kwargs.get("legpos", self.legpos[nax])
301
+ if self.legpos[nax] is not None:
302
+ copy_label: str | None = kwargs.get("label")
303
+ kwargs["label"] = None
304
+ self.LegendManager.legend(ax, check=False, fromplot=True, **kwargs)
305
+ kwargs["label"] = copy_label
306
+
307
+ # If tight_layout is enabled, is re-inforced
308
+ if self.tight:
309
+ self.fig.tight_layout()
310
+
311
+ # End of the function
@@ -0,0 +1,242 @@
1
+ """RangeManager class."""
2
+
3
+ import warnings
4
+
5
+ import numpy as np
6
+ from matplotlib.axes import Axes
7
+ from numpy.typing import NDArray
8
+
9
+ from pyPLUTO.imagemixin import ImageMixin
10
+ from pyPLUTO.imagestate import ImageState
11
+
12
+
13
+ class RangeManager(ImageMixin):
14
+ """RangeManager class.
15
+
16
+ It provides methods to set the x and y axis limits for a set of axes in a
17
+ plot.
18
+ """
19
+
20
+ def __init__(self, state: ImageState) -> None:
21
+ """Initialize the RangeManager with the given state."""
22
+ self.state = state
23
+ self.changerange = 0
24
+ self.adaptrange = 2
25
+ self.fixrange = 3
26
+
27
+ def set_xrange(
28
+ self, ax: Axes, nax: int, xlim: list[float], case: int
29
+ ) -> None:
30
+ """Set the lower and upper limits of the x-axis of a set of axes.
31
+
32
+ Returns
33
+ -------
34
+ - None
35
+
36
+ Parameters
37
+ ----------
38
+ - ax (not optional): ax
39
+ The selected set of axes.
40
+ - case (not optional): int
41
+ The case in exam (if range is fixed or variable).
42
+ - nax (not optional): int
43
+ The number of the selected set of axes.
44
+ - xlim (not optional): list[float]
45
+ The limits of the x-axis.
46
+
47
+ ----
48
+
49
+ Examples
50
+ --------
51
+ - Example #1: Set the x-axis limits of the selected set of axes
52
+
53
+ >>> _set_xrange(ax, nax, xlim, case)
54
+
55
+ """
56
+ # Case 0: the x-axis limits are set automatically (no previous limit)
57
+ if case == self.changerange:
58
+ ax.set_xlim(xlim[0], xlim[1])
59
+
60
+ # Case switched to 2 (previous limits are present now)
61
+ self.setax[nax] = 2
62
+
63
+ # Case 1: limits are already set and they should not be changed
64
+ # (aka do nothing)
65
+
66
+ # Case 2: the x-axis limit are changed automatically
67
+ # (previous limit present)
68
+ if case == self.adaptrange:
69
+ xmin = min(xlim[0], ax.get_xlim()[0])
70
+ xmax = max(xlim[1], ax.get_xlim()[1])
71
+ ax.set_xlim(xmin, xmax)
72
+
73
+ # Case 3: x-axis limits are set manually
74
+ if case == self.fixrange:
75
+ ax.set_xlim(xlim[0], xlim[1])
76
+
77
+ # Case switched to 1 (no change unless stated explicitly otherwise)
78
+ self.setax[nax] = 1
79
+
80
+ # End of the function
81
+
82
+ def set_yrange(
83
+ self,
84
+ ax: Axes,
85
+ nax: int,
86
+ ylim: list[float],
87
+ case: int,
88
+ data: tuple[NDArray[np.float64] | None, NDArray[np.float64] | None] = (
89
+ None,
90
+ None,
91
+ ),
92
+ # x: NDArray[np.float64] | None = None,
93
+ # y: NDArray[np.float64] | None = None,
94
+ ) -> None:
95
+ """Set the lower and upper limits of the y-axis of a set of.
96
+
97
+ Unlike the x-axis, the y-axis limits are recovered depending on both the
98
+ x-data and the y-data.
99
+
100
+ Returns
101
+ -------
102
+ - None
103
+
104
+ Parameters
105
+ ----------
106
+ - ax (not optional): ax
107
+ The selected set of axes.
108
+ - case (not optional): int
109
+ The case in exam (if range is fixed or variable).
110
+ - nax (not optional): int
111
+ The number of the selected set of axes.
112
+ - x: np.ndarray
113
+ The x-array (to limit the y-range automatically).
114
+ - y: np.ndarray
115
+ The y-array (to limit the y-range automatically).
116
+ - ylim (not optional): list[float]
117
+ The limits of the y-axis.
118
+
119
+
120
+ ----
121
+
122
+ Examples
123
+ --------
124
+ - Example #1: Set the y-axis limits of the selected set of axes
125
+
126
+ >>> _set_yrange(ax, nax, ylim, case)
127
+
128
+ """
129
+ x, y = data
130
+ # Case 0: the y-axis limits are set automatically (no previous limit)
131
+ if case == self.changerange:
132
+ if x is None or y is None:
133
+ raise ValueError("x and y arrays must be provided if case is 0")
134
+
135
+ # Find the limits of the x-axis
136
+ yrange = np.where(np.logical_and(x >= x.min(), x <= x.max()))
137
+ smally = y[yrange]
138
+
139
+ # Extend slightly the range
140
+ ymin, ymax = self.range_offset(
141
+ smally.min(), smally.max(), self.yscale[nax]
142
+ )
143
+ # ymin = smally.min() - 0.02*np.abs(smally.min())
144
+ # ymax = smally.max() + 0.02*np.abs(smally.max())
145
+ ax.set_ylim(ymin, ymax)
146
+
147
+ # Switch to case 2 (previous limits are present now)
148
+ self.setay[nax] = 2
149
+
150
+ # Case 1: limits are already set and they should not be changed
151
+ # (aka do nothing)
152
+
153
+ # Case 2: the y-axis limit are changed automatically
154
+ # (previous limit present)
155
+ if case == self.adaptrange:
156
+ if x is None or y is None:
157
+ raise ValueError("x and y arrays must be provided if case is 2")
158
+
159
+ # Find the limits of the x-axis
160
+ yrange = np.where(np.logical_and(x >= x.min(), x <= x.max()))
161
+ smally = y[yrange]
162
+
163
+ # Extend slightly the range (not perfect method)
164
+ ymin, ymax = self.range_offset(
165
+ smally.min(), smally.max(), self.yscale[nax]
166
+ )
167
+ # ymin = smally.min() - 0.02*np.abs(smally.min())
168
+ # ymax = smally.max() + 0.02*np.abs(smally.max())
169
+
170
+ # Check if the limits should be changed
171
+ ymin = np.minimum(ymin, ax.get_ylim()[0])
172
+ ymax = np.maximum(ymax, ax.get_ylim()[1])
173
+ ax.set_ylim(ymin, ymax)
174
+
175
+ # Case 3: y-axis limits must be set manually
176
+ if case == self.fixrange:
177
+ ax.set_ylim(ylim[0], ylim[1])
178
+
179
+ # Case switched to 1 (no change unless stated explicitly otherwise)
180
+ self.setay[nax] = 1
181
+
182
+ # End of the function
183
+
184
+ def range_offset(
185
+ self, ymin: float, ymax: float, scale: str, margin: float = 0.1
186
+ ) -> tuple[float, float]:
187
+ """Return the offsetted data range for the y-axis limits.
188
+
189
+ Returns
190
+ -------
191
+ - ymin: float
192
+ The lower limit of the y-axis.
193
+ - ymax: float
194
+ The upper limit of the y-axis.
195
+
196
+ Parameters
197
+ ----------
198
+ - ymin (not optional): float
199
+ The lower limit of the y-axis.
200
+ - ymax (not optional): float
201
+ The upper limit of the y-axis.
202
+ - scale (not optional): str
203
+ The scale of the y-axis.
204
+ - margin (optional): float
205
+ The margin of the data range.
206
+
207
+ ----
208
+
209
+ Examples
210
+ --------
211
+ - Example #1: Set the y-axis limits of the selected set of axes
212
+
213
+ >>> ymin, ymax = _range_offset(ymin, ymax, scale)
214
+
215
+ """
216
+ # Find the data range
217
+ data_range = ymax - ymin
218
+ if data_range == 0:
219
+ data_range = ymax * 0.1
220
+
221
+ # Find the padding (with non-inear scale adjustments)
222
+ padding = margin * data_range
223
+ range_maxval = 10
224
+ if np.log10(np.abs(data_range)) > range_maxval and scale != "linear":
225
+ padding *= 2 * np.abs(np.log10(np.abs(data_range)))
226
+ print(padding)
227
+
228
+ # Set the limits (additional check if the scale is logarithmic)
229
+ if scale in ["linear", "symlog", "asinh"]:
230
+ return (ymin - padding, ymax + padding)
231
+ if scale == "log":
232
+ if ymin <= 0 or ymax <= 0:
233
+ ymin = min(np.abs(ymin), np.abs(ymax))
234
+ ymax = max(np.abs(ymin), np.abs(ymax))
235
+ warnings.warn(
236
+ "Negative range for logarithmic scale!",
237
+ UserWarning,
238
+ stacklevel=2,
239
+ )
240
+ return (max(ymin - padding, ymin * 0.5), ymax + padding)
241
+
242
+ return (ymin, ymax)