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.
- pyPLUTO/__init__.py +22 -0
- pyPLUTO/amr.py +745 -0
- pyPLUTO/baseloadmixin.py +258 -0
- pyPLUTO/baseloadstate.py +45 -0
- pyPLUTO/codes/echo_load.py +161 -0
- pyPLUTO/configure.py +261 -0
- pyPLUTO/gui/config.py +174 -0
- pyPLUTO/gui/custom_var.py +435 -0
- pyPLUTO/gui/globals.py +108 -0
- pyPLUTO/gui/main.py +17 -0
- pyPLUTO/gui/main_window.py +177 -0
- pyPLUTO/gui/panels.py +66 -0
- pyPLUTO/gui/utils.py +273 -0
- pyPLUTO/h_pypluto.py +84 -0
- pyPLUTO/image.py +302 -0
- pyPLUTO/imagefuncs/colorbar.py +240 -0
- pyPLUTO/imagefuncs/contour.py +254 -0
- pyPLUTO/imagefuncs/create_axes.py +464 -0
- pyPLUTO/imagefuncs/display.py +306 -0
- pyPLUTO/imagefuncs/figure.py +395 -0
- pyPLUTO/imagefuncs/imagetools.py +487 -0
- pyPLUTO/imagefuncs/interactive.py +403 -0
- pyPLUTO/imagefuncs/legend.py +250 -0
- pyPLUTO/imagefuncs/plot.py +311 -0
- pyPLUTO/imagefuncs/range.py +242 -0
- pyPLUTO/imagefuncs/scatter.py +270 -0
- pyPLUTO/imagefuncs/set_axis.py +497 -0
- pyPLUTO/imagefuncs/streamplot.py +297 -0
- pyPLUTO/imagefuncs/zoom.py +428 -0
- pyPLUTO/imagemixin.py +259 -0
- pyPLUTO/imagestate.py +45 -0
- pyPLUTO/load.py +447 -0
- pyPLUTO/loadfuncs/baseloadtools.py +71 -0
- pyPLUTO/loadfuncs/codeselection.py +48 -0
- pyPLUTO/loadfuncs/defpluto.py +123 -0
- pyPLUTO/loadfuncs/descriptor.py +102 -0
- pyPLUTO/loadfuncs/findfiles.py +182 -0
- pyPLUTO/loadfuncs/findformat.py +245 -0
- pyPLUTO/loadfuncs/initload.py +203 -0
- pyPLUTO/loadfuncs/loadvars.py +227 -0
- pyPLUTO/loadfuncs/offsetdata.py +87 -0
- pyPLUTO/loadfuncs/offsetfluid.py +408 -0
- pyPLUTO/loadfuncs/read_files.py +213 -0
- pyPLUTO/loadfuncs/readdata.py +619 -0
- pyPLUTO/loadfuncs/readdata_old.py +567 -0
- pyPLUTO/loadfuncs/readdefplini.py +101 -0
- pyPLUTO/loadfuncs/readfluid.py +479 -0
- pyPLUTO/loadfuncs/readformat.py +277 -0
- pyPLUTO/loadfuncs/readgridalone.py +224 -0
- pyPLUTO/loadfuncs/readgridfile.py +255 -0
- pyPLUTO/loadfuncs/readgridout.py +451 -0
- pyPLUTO/loadfuncs/readpart.py +419 -0
- pyPLUTO/loadfuncs/readtab.py +105 -0
- pyPLUTO/loadfuncs/write_files.py +283 -0
- pyPLUTO/loadmixin.py +419 -0
- pyPLUTO/loadpart.py +233 -0
- pyPLUTO/loadstate.py +68 -0
- pyPLUTO/newload.py +81 -0
- pyPLUTO/pytools.py +145 -0
- pyPLUTO/toolfuncs/findlines.py +551 -0
- pyPLUTO/toolfuncs/fourier.py +149 -0
- pyPLUTO/toolfuncs/nabla.py +676 -0
- pyPLUTO/toolfuncs/parttools.py +152 -0
- pyPLUTO/toolfuncs/transform.py +638 -0
- pyPLUTO/utils/annotator.py +27 -0
- pyPLUTO/utils/inspector.py +145 -0
- pyPLUTO/utils/make_docstrings.py +3 -0
- py_pluto-1.1.4.dist-info/METADATA +218 -0
- py_pluto-1.1.4.dist-info/RECORD +73 -0
- py_pluto-1.1.4.dist-info/WHEEL +5 -0
- py_pluto-1.1.4.dist-info/entry_points.txt +2 -0
- py_pluto-1.1.4.dist-info/licenses/LICENSE +27 -0
- py_pluto-1.1.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"""ScatterManager class."""
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from matplotlib.collections import PathCollection
|
|
7
|
+
from numpy.typing import NDArray
|
|
8
|
+
|
|
9
|
+
from pyPLUTO.imagefuncs.colorbar import ColorbarManager
|
|
10
|
+
from pyPLUTO.imagefuncs.imagetools import ImageToolsManager
|
|
11
|
+
from pyPLUTO.imagefuncs.legend import LegendManager
|
|
12
|
+
from pyPLUTO.imagefuncs.range import RangeManager
|
|
13
|
+
from pyPLUTO.imagefuncs.set_axis import AxisManager
|
|
14
|
+
from pyPLUTO.imagemixin import ImageMixin
|
|
15
|
+
from pyPLUTO.imagestate import ImageState
|
|
16
|
+
from pyPLUTO.utils.inspector import track_kwargs
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ScatterManager(ImageMixin):
|
|
20
|
+
"""Manager for the scatter plot of a 2D function.
|
|
21
|
+
|
|
22
|
+
A simple figure and a single axis can also be created.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
exposed_methods = ("scatter",)
|
|
26
|
+
|
|
27
|
+
def __init__(self, state: ImageState) -> None:
|
|
28
|
+
"""Initialize the ScatterManager with the given state."""
|
|
29
|
+
self.state = state
|
|
30
|
+
|
|
31
|
+
self.AxisManager = AxisManager(state)
|
|
32
|
+
self.ColorbarManager = ColorbarManager(state)
|
|
33
|
+
self.ImageToolsManager = ImageToolsManager(state)
|
|
34
|
+
self.LegendManager = LegendManager(state)
|
|
35
|
+
self.RangeManager = RangeManager(state)
|
|
36
|
+
|
|
37
|
+
@track_kwargs
|
|
38
|
+
def scatter(
|
|
39
|
+
self,
|
|
40
|
+
x: NDArray[np.generic] | list[float],
|
|
41
|
+
y: NDArray[np.generic] | list[float],
|
|
42
|
+
check: bool = True,
|
|
43
|
+
**kwargs: Any,
|
|
44
|
+
) -> PathCollection:
|
|
45
|
+
"""Scatter plot for a 2D function (or a 2D slice).
|
|
46
|
+
|
|
47
|
+
A simple figure and a single axis can also be created.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
- The scatter plot
|
|
52
|
+
|
|
53
|
+
Parameters
|
|
54
|
+
----------
|
|
55
|
+
- alpha: float, default 1.0
|
|
56
|
+
Sets the transparency of the plot.
|
|
57
|
+
- aspect: {'auto', 'equal', float}, default 'auto'
|
|
58
|
+
Sets the aspect ratio of the plot. The 'auto' keyword is the default
|
|
59
|
+
option (most likely the plot will be squared). The 'equal' keyword
|
|
60
|
+
will set the same scaling for x and y. A float will fix the ratio
|
|
61
|
+
between the y-scale and the x-scale (1.0 is the same as 'equal').
|
|
62
|
+
- ax: axis object
|
|
63
|
+
The axis where to plot the scatter. If not given, the last considered
|
|
64
|
+
axis will be used.
|
|
65
|
+
- c: str, default self.color
|
|
66
|
+
Determines the scatter plot color. If not defined, the program will
|
|
67
|
+
loop over an array of 6 color which are different for the most
|
|
68
|
+
common vision deficiencies.
|
|
69
|
+
- clabel: str, default None
|
|
70
|
+
Sets the colorbar label.
|
|
71
|
+
- cmap: str, default 'hot'
|
|
72
|
+
Selects the colormap. If not defined, the colormap 'hot' will be
|
|
73
|
+
adopted. Some useful colormaps are: plasma, magma, seismic. Please
|
|
74
|
+
avoid using colorbars like jjet or rainbow, which are not
|
|
75
|
+
perceptively uniform and not suited for people with vision
|
|
76
|
+
deficiencies.
|
|
77
|
+
|
|
78
|
+
- cpos: {'top','bottom','left','right'}, default None
|
|
79
|
+
Enables the colorbar (if defined), default position on the right.
|
|
80
|
+
- cscale: {'linear','log','symlog','twoslope'}, default 'linear'
|
|
81
|
+
Sets the colorbar scale. Default is the linear ('norm') scale.
|
|
82
|
+
- edgecolors: str, default None
|
|
83
|
+
Enables a contouring color for the markers.
|
|
84
|
+
- fontsize: float, default 17.0
|
|
85
|
+
Sets the fontsize for all the axis components (only for the current
|
|
86
|
+
axis).
|
|
87
|
+
- grid: bool, default False
|
|
88
|
+
Enables/disables the grid on the plot.
|
|
89
|
+
- label: str, default None
|
|
90
|
+
Associates a label to be used for the creation of the legend.
|
|
91
|
+
- labelsize: float, default fontsize
|
|
92
|
+
Sets the labels fontsize (which is the same for both labels).
|
|
93
|
+
The default value corresponds to the value of the keyword
|
|
94
|
+
'fontsize'.
|
|
95
|
+
- legpos: int/str, default None
|
|
96
|
+
If enabled, creates a legend. This keyword selects the legend
|
|
97
|
+
location.
|
|
98
|
+
- marker: {'o', 'v', '^', '<', '>', 'X', ' ', etc.}, default ' '
|
|
99
|
+
Sets an optional symbol for every point. The default value is no
|
|
100
|
+
marker (' ').
|
|
101
|
+
- minorticks: str, default None
|
|
102
|
+
If not None enables the minor ticks on the plot (for both grid
|
|
103
|
+
axes).
|
|
104
|
+
- ms: float, default 3
|
|
105
|
+
Sets the marker size.
|
|
106
|
+
- ticksdir: {'in', 'out'}, default 'in'
|
|
107
|
+
Sets the ticks direction. The default option is 'in'.
|
|
108
|
+
- tickssize: float | bool, default True
|
|
109
|
+
Sets the ticks fontsize (which is the same for both grid axes).
|
|
110
|
+
The default value corresponds to the value of the keyword
|
|
111
|
+
'fontsize'.
|
|
112
|
+
- title: str, default None
|
|
113
|
+
Places the title of the plot on top of it.
|
|
114
|
+
- titlepad: float, default 8.0
|
|
115
|
+
Sets the distance between the title and the top of the plot
|
|
116
|
+
- titlesize: float, default fontsize
|
|
117
|
+
Sets the title fontsize. The default value corresponds to the value
|
|
118
|
+
of the keyword 'fontsize'.
|
|
119
|
+
- tresh: float, default max(abs(vmin),vmax)*0.01
|
|
120
|
+
Sets the threshold for the colormap. If not defined, the threshold
|
|
121
|
+
will be set to 1% of the maximum absolute value of the variable.
|
|
122
|
+
The default cases are the following:
|
|
123
|
+
- twoslope colorscale: sets the limit between the two linear
|
|
124
|
+
regimes.
|
|
125
|
+
- symlog: sets the limit between the logaitrhmic and the linear
|
|
126
|
+
regime.
|
|
127
|
+
- vmax: float
|
|
128
|
+
The maximum value of the colormap.
|
|
129
|
+
- vmin: float
|
|
130
|
+
The minimum value of the colormap.
|
|
131
|
+
- x (not optional): 1D array
|
|
132
|
+
The x-axis variable.
|
|
133
|
+
- xrange: [float, float], default 'Default'
|
|
134
|
+
Sets the range in the x-direction. If not defined or set to
|
|
135
|
+
'Default' the code will compute the range while plotting the data by
|
|
136
|
+
taking the minimum and the maximum values of the x1-array.
|
|
137
|
+
- xscale: {'linear','log'}, default 'linear'
|
|
138
|
+
If enabled (and different from True), sets automatically the scale
|
|
139
|
+
on the x-axis. Data in log scale should be used with the keyword
|
|
140
|
+
'log', while data in linear scale should be used with the keyword
|
|
141
|
+
'linear'.
|
|
142
|
+
- xticks: {[float], None, True}, default True
|
|
143
|
+
If enabled (and different from True), sets manually ticks on
|
|
144
|
+
x-axis. In order to completely remove the ticks the keyword should
|
|
145
|
+
be used with None.
|
|
146
|
+
- xtickslabels: {[str], None, True}, default True
|
|
147
|
+
If enabled (and different from True), sets manually the ticks
|
|
148
|
+
labels on the x-axis. In order to completely remove the ticks the
|
|
149
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
150
|
+
always correspond to fixed ticks.
|
|
151
|
+
- xtitle: str, default None
|
|
152
|
+
Sets and places the label of the x-axis.
|
|
153
|
+
- y (not optional): 1D array
|
|
154
|
+
The y-axis variable.
|
|
155
|
+
- yrange: [float, float], default [0,1]
|
|
156
|
+
Sets the range in the y-direction. If not defined the code will
|
|
157
|
+
compute the range while plotting the data.
|
|
158
|
+
- yscale: {'linear','log'}, default 'linear'
|
|
159
|
+
If enabled (and different from True), sets automatically the scale
|
|
160
|
+
on the y-axis. Data in log scale should be used with the keyword
|
|
161
|
+
'log', while data in linear scale should be used with the keyword
|
|
162
|
+
'linear'.
|
|
163
|
+
- yticks: {[float], None, True}, default True
|
|
164
|
+
If enabled (and different from True), sets manually ticks on
|
|
165
|
+
y-axis. In order to completely remove the ticks the keyword should
|
|
166
|
+
be used with None.
|
|
167
|
+
- ytickslabels: {[str], None, True}, default True
|
|
168
|
+
If enabled (and different from True), sets manually the ticks
|
|
169
|
+
labels on the y-axis. In order to completely remove the ticks the
|
|
170
|
+
keyword should be used with None. Note that fixed tickslabels should
|
|
171
|
+
always correspond to fixed ticks.
|
|
172
|
+
- ytitle: str, default None
|
|
173
|
+
Sets and places the label of the y-axis.
|
|
174
|
+
|
|
175
|
+
----
|
|
176
|
+
|
|
177
|
+
Examples
|
|
178
|
+
--------
|
|
179
|
+
- Example #1: Plot a scatter plot of a variable
|
|
180
|
+
|
|
181
|
+
>>> I.scatter(x, y)
|
|
182
|
+
|
|
183
|
+
- Example #2: Plot a scatter plot of a variable with a colorbar
|
|
184
|
+
|
|
185
|
+
>>> I.scatter(x, y, cmap="hot", c=x**2 + y**2, cpos="right")
|
|
186
|
+
|
|
187
|
+
"""
|
|
188
|
+
# Convert x and y to numpy arrays (if necessary)
|
|
189
|
+
x = np.asarray(x)
|
|
190
|
+
y = np.asarray(y)
|
|
191
|
+
|
|
192
|
+
kwargs.pop("check", check)
|
|
193
|
+
|
|
194
|
+
# Set or create figure and axes
|
|
195
|
+
ax, nax = self.ImageToolsManager.assign_ax(
|
|
196
|
+
kwargs.pop("ax", None), **kwargs
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
if self.fig is None:
|
|
200
|
+
raise ValueError(
|
|
201
|
+
"No figure is present. Please create a figure first."
|
|
202
|
+
)
|
|
203
|
+
# Keywords xrange and yrange
|
|
204
|
+
if not kwargs.get("xrange") and self.setax[nax] != 1:
|
|
205
|
+
kwargs["xrange"] = [x.min(), x.max()]
|
|
206
|
+
if not kwargs.get("yrange") and self.setay[nax] != 1:
|
|
207
|
+
kwargs["yrange"] = [y.min(), y.max()]
|
|
208
|
+
|
|
209
|
+
# Set ax parameters
|
|
210
|
+
self.AxisManager.set_axis(ax=ax, check=False, **kwargs)
|
|
211
|
+
self.ImageToolsManager.hide_text(nax, ax.texts)
|
|
212
|
+
|
|
213
|
+
# Keywords vmin and vmax
|
|
214
|
+
c = kwargs.get("c")
|
|
215
|
+
# If c is a list convert to array
|
|
216
|
+
vmin = (
|
|
217
|
+
kwargs.get("vmin", 0.0)
|
|
218
|
+
if c is None or isinstance(c, str)
|
|
219
|
+
else kwargs.get("vmin", np.nanmin(np.asarray(c)))
|
|
220
|
+
)
|
|
221
|
+
vmax = (
|
|
222
|
+
kwargs.get("vmax", 0.0)
|
|
223
|
+
if c is None or isinstance(c, str)
|
|
224
|
+
else kwargs.get("vmax", np.nanmax(np.asarray(c)))
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
# Keyword for colorbar and colorscale
|
|
228
|
+
cpos = kwargs.get("cpos")
|
|
229
|
+
cscale = kwargs.get("cscale", "norm")
|
|
230
|
+
tresh = kwargs.get("tresh", max(np.abs(vmin), vmax) * 0.01)
|
|
231
|
+
self.vlims[nax] = [vmin, vmax, tresh]
|
|
232
|
+
|
|
233
|
+
# Set the colorbar scale
|
|
234
|
+
if not isinstance(c, str) and c is not None:
|
|
235
|
+
norm = self.ImageToolsManager.set_cscale(cscale, vmin, vmax, tresh)
|
|
236
|
+
cmap = self.ImageToolsManager.find_cmap(kwargs.get("cmap"))
|
|
237
|
+
else:
|
|
238
|
+
norm = None
|
|
239
|
+
cmap = None
|
|
240
|
+
|
|
241
|
+
# Start scatter plot procedure
|
|
242
|
+
pcm = ax.scatter(
|
|
243
|
+
x,
|
|
244
|
+
y,
|
|
245
|
+
cmap=cmap,
|
|
246
|
+
norm=norm,
|
|
247
|
+
c=c,
|
|
248
|
+
s=kwargs.get("ms", 3),
|
|
249
|
+
edgecolors=kwargs.get("edgecolors", "none"),
|
|
250
|
+
alpha=kwargs.get("alpha", 1.0),
|
|
251
|
+
marker=kwargs.get("marker", "o"),
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
# Creation of the legend
|
|
255
|
+
self.legpos[nax] = kwargs.get("legpos", self.legpos[nax])
|
|
256
|
+
if self.legpos[nax] is not None:
|
|
257
|
+
copy_label = kwargs.get("label")
|
|
258
|
+
kwargs["label"] = None
|
|
259
|
+
self.LegendManager.legend(ax, check=False, fromplot=True, **kwargs)
|
|
260
|
+
kwargs["label"] = copy_label
|
|
261
|
+
|
|
262
|
+
# Place the colorbar (use colorbar function)
|
|
263
|
+
if cpos is not None:
|
|
264
|
+
self.ColorbarManager.colorbar(pcm, check=False, **kwargs)
|
|
265
|
+
|
|
266
|
+
# If tight_layout is enabled, is re-inforced
|
|
267
|
+
if self.tight:
|
|
268
|
+
self.fig.tight_layout()
|
|
269
|
+
|
|
270
|
+
return pcm
|