gsplot 0.0.1__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.
- gsplot/__init__.py +98 -0
- gsplot/base/base.py +518 -0
- gsplot/base/base_alias_validator.py +155 -0
- gsplot/color/colormap.py +218 -0
- gsplot/config/config.py +422 -0
- gsplot/data/load_file.py +188 -0
- gsplot/figure/axes.py +361 -0
- gsplot/figure/axes_base.py +952 -0
- gsplot/figure/figure_tools.py +66 -0
- gsplot/figure/show.py +205 -0
- gsplot/figure/store.py +119 -0
- gsplot/hello_world/hello_world.py +23 -0
- gsplot/logger.py +155 -0
- gsplot/path/path.py +227 -0
- gsplot/plot/line.py +328 -0
- gsplot/plot/line_base.py +272 -0
- gsplot/plot/line_colormap_base.py +120 -0
- gsplot/plot/line_colormap_dashed.py +540 -0
- gsplot/plot/line_colormap_solid.py +289 -0
- gsplot/plot/scatter.py +228 -0
- gsplot/plot/scatter_colormap.py +296 -0
- gsplot/style/graph.py +466 -0
- gsplot/style/label.py +866 -0
- gsplot/style/legend.py +469 -0
- gsplot/style/legend_colormap.py +381 -0
- gsplot/style/ticks.py +167 -0
- gsplot/version.py +2 -0
- gsplot-0.0.1.dist-info/LICENSE +21 -0
- gsplot-0.0.1.dist-info/METADATA +82 -0
- gsplot-0.0.1.dist-info/RECORD +31 -0
- gsplot-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import numpy as np
|
|
5
|
+
from matplotlib.artist import Artist
|
|
6
|
+
from matplotlib.axes import Axes
|
|
7
|
+
from matplotlib.legend import Legend as Lg
|
|
8
|
+
from matplotlib.legend_handler import HandlerBase
|
|
9
|
+
from matplotlib.patches import Rectangle
|
|
10
|
+
|
|
11
|
+
from ..base.base import CreateClassParams, ParamsGetter, bind_passed_params
|
|
12
|
+
from ..color.colormap import Colormap
|
|
13
|
+
from ..figure.axes_base import AxesResolver
|
|
14
|
+
from ..plot.line import Line
|
|
15
|
+
from .legend import Legend
|
|
16
|
+
|
|
17
|
+
__all__: list[str] = ["legend_colormap"]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class HandlerColormap(HandlerBase):
|
|
21
|
+
"""
|
|
22
|
+
Custom legend handler for displaying a colormap.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
--------------------
|
|
26
|
+
cmap : str
|
|
27
|
+
The colormap to use.
|
|
28
|
+
num_stripes : int, default=8
|
|
29
|
+
Number of stripes in the colormap legend.
|
|
30
|
+
vmin : int | float, default=0
|
|
31
|
+
Minimum value for the colormap.
|
|
32
|
+
vmax : int | float, default=1
|
|
33
|
+
Maximum value for the colormap.
|
|
34
|
+
reverse : bool, default=False
|
|
35
|
+
Whether to reverse the colormap.
|
|
36
|
+
**kwargs : Any
|
|
37
|
+
Additional parameters for the `Rectangle` artists.
|
|
38
|
+
|
|
39
|
+
Examples
|
|
40
|
+
--------------------
|
|
41
|
+
>>> from matplotlib.legend_handler import HandlerColormap
|
|
42
|
+
>>> handler = HandlerColormap(cmap="viridis", num_stripes=10, reverse=True)
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
cmap: str,
|
|
48
|
+
num_stripes: int = 8,
|
|
49
|
+
vmin: int | float = 0,
|
|
50
|
+
vmax: int | float = 1,
|
|
51
|
+
reverse: bool = False,
|
|
52
|
+
**kwargs,
|
|
53
|
+
):
|
|
54
|
+
super().__init__(**kwargs)
|
|
55
|
+
self.cmap: str = cmap
|
|
56
|
+
self.num_stripes: int = num_stripes
|
|
57
|
+
self.vmin: int | float = vmin
|
|
58
|
+
self.vmax: int | float = vmax
|
|
59
|
+
self.reverse: bool = reverse
|
|
60
|
+
self.kwargs = kwargs
|
|
61
|
+
|
|
62
|
+
def create_artists(
|
|
63
|
+
self,
|
|
64
|
+
legend,
|
|
65
|
+
orig_handle,
|
|
66
|
+
xdescent,
|
|
67
|
+
ydescent,
|
|
68
|
+
width,
|
|
69
|
+
height,
|
|
70
|
+
fontsize,
|
|
71
|
+
trans,
|
|
72
|
+
):
|
|
73
|
+
"""
|
|
74
|
+
Create colormap legend artists.
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
--------------------
|
|
78
|
+
legend : Legend
|
|
79
|
+
The legend instance.
|
|
80
|
+
orig_handle : Any
|
|
81
|
+
The original handle used for the legend.
|
|
82
|
+
xdescent : float
|
|
83
|
+
Horizontal offset for the legend element.
|
|
84
|
+
ydescent : float
|
|
85
|
+
Vertical offset for the legend element.
|
|
86
|
+
width : float
|
|
87
|
+
Width of the legend element.
|
|
88
|
+
height : float
|
|
89
|
+
Height of the legend element.
|
|
90
|
+
fontsize : float
|
|
91
|
+
Font size for the legend text.
|
|
92
|
+
trans : Transform
|
|
93
|
+
Transformation applied to the artist.
|
|
94
|
+
|
|
95
|
+
Returns
|
|
96
|
+
--------------------
|
|
97
|
+
list[Rectangle]
|
|
98
|
+
A list of rectangles representing the colormap legend.
|
|
99
|
+
|
|
100
|
+
Examples
|
|
101
|
+
--------------------
|
|
102
|
+
Used internally for creating custom colormap legend patches.
|
|
103
|
+
"""
|
|
104
|
+
stripes = []
|
|
105
|
+
cmap_ndarray = np.linspace(self.vmin, self.vmax, self.num_stripes)
|
|
106
|
+
cmap_list = Colormap(
|
|
107
|
+
cmap=self.cmap, cmap_data=cmap_ndarray, normalize=False, reverse=False
|
|
108
|
+
).get_split_cmap()
|
|
109
|
+
|
|
110
|
+
for i in range(self.num_stripes):
|
|
111
|
+
fc = cmap_list[self.num_stripes - i - 1] if self.reverse else cmap_list[i]
|
|
112
|
+
s = Rectangle(
|
|
113
|
+
(xdescent + i * width / self.num_stripes, ydescent),
|
|
114
|
+
width / self.num_stripes,
|
|
115
|
+
height,
|
|
116
|
+
fc=fc,
|
|
117
|
+
transform=trans,
|
|
118
|
+
**self.kwargs,
|
|
119
|
+
)
|
|
120
|
+
stripes.append(s)
|
|
121
|
+
return stripes
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class LegendColormap:
|
|
125
|
+
"""
|
|
126
|
+
Adds a colormap legend to a Matplotlib axis.
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
--------------------
|
|
130
|
+
axis_target : int | Axes
|
|
131
|
+
The target axis for the colormap legend.
|
|
132
|
+
cmap : str, default="viridis"
|
|
133
|
+
The colormap to use.
|
|
134
|
+
label : str | None, default=None
|
|
135
|
+
Label for the legend.
|
|
136
|
+
num_stripes : int, default=8
|
|
137
|
+
Number of stripes in the colormap legend.
|
|
138
|
+
vmin : int | float, default=0
|
|
139
|
+
Minimum value for the colormap.
|
|
140
|
+
vmax : int | float, default=1
|
|
141
|
+
Maximum value for the colormap.
|
|
142
|
+
reverse : bool, default=False
|
|
143
|
+
Whether to reverse the colormap.
|
|
144
|
+
**kwargs : Any
|
|
145
|
+
Additional parameters passed to the handler and artists.
|
|
146
|
+
|
|
147
|
+
Examples
|
|
148
|
+
--------------------
|
|
149
|
+
>>> from matplotlib import pyplot as plt
|
|
150
|
+
>>> import numpy as np
|
|
151
|
+
>>> fig, ax = plt.subplots()
|
|
152
|
+
>>> x = np.linspace(0, 10, 100)
|
|
153
|
+
>>> y = np.sin(x)
|
|
154
|
+
>>> ax.plot(x, y, label="Data")
|
|
155
|
+
>>> LegendColormap(0, cmap="plasma", label="Colormap Legend").legend_colormap()
|
|
156
|
+
>>> plt.show()
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
def __init__(
|
|
160
|
+
self,
|
|
161
|
+
axis_target: int | Axes,
|
|
162
|
+
cmap: str = "viridis",
|
|
163
|
+
label: str | None = None,
|
|
164
|
+
num_stripes: int = 8,
|
|
165
|
+
vmin: int | float = 0,
|
|
166
|
+
vmax: int | float = 1,
|
|
167
|
+
reverse: bool = False,
|
|
168
|
+
**kwargs: Any,
|
|
169
|
+
):
|
|
170
|
+
self.axis_target: int | Axes = axis_target
|
|
171
|
+
self.cmap: str = cmap
|
|
172
|
+
self.label: str | None = label
|
|
173
|
+
self.num_stripes: int = num_stripes
|
|
174
|
+
self.vmin: int | float = vmin
|
|
175
|
+
self.vmax: int | float = vmax
|
|
176
|
+
self.reverse: bool = reverse
|
|
177
|
+
self.kwargs: Any = kwargs
|
|
178
|
+
|
|
179
|
+
_axes_resolver = AxesResolver(axis_target)
|
|
180
|
+
self.axis_index: int = _axes_resolver.axis_index
|
|
181
|
+
self.axis: Axes = _axes_resolver.axis
|
|
182
|
+
|
|
183
|
+
MAX_NUM_STRIPES = 256
|
|
184
|
+
if self.num_stripes > MAX_NUM_STRIPES:
|
|
185
|
+
self.num_stripes = MAX_NUM_STRIPES
|
|
186
|
+
|
|
187
|
+
self.handler_colormap = HandlerColormap(
|
|
188
|
+
cmap=self.cmap,
|
|
189
|
+
num_stripes=self.num_stripes,
|
|
190
|
+
reverse=self.reverse,
|
|
191
|
+
vmin=self.vmin,
|
|
192
|
+
vmax=self.vmax,
|
|
193
|
+
**self.kwargs,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
def get_legend_handlers_colormap(
|
|
197
|
+
self,
|
|
198
|
+
) -> tuple[list[Rectangle], list[str | None], dict[Rectangle, HandlerColormap]]:
|
|
199
|
+
"""
|
|
200
|
+
Get legend handlers, labels, and handler mappings for colormap legend.
|
|
201
|
+
|
|
202
|
+
Returns
|
|
203
|
+
--------------------
|
|
204
|
+
tuple
|
|
205
|
+
- handles (list[Rectangle]): List of legend handles.
|
|
206
|
+
- labels (list[str | None]): List of legend labels.
|
|
207
|
+
- handlers (dict[Rectangle, HandlerColormap]): Mapping of handles to their handlers.
|
|
208
|
+
|
|
209
|
+
Examples
|
|
210
|
+
--------------------
|
|
211
|
+
>>> legend_colormap = LegendColormap(0, cmap="plasma", num_stripes=8)
|
|
212
|
+
>>> handles, labels, handlers = legend_colormap.get_legend_handlers_colormap()
|
|
213
|
+
>>> print(handles, labels, handlers)
|
|
214
|
+
"""
|
|
215
|
+
handle = [Rectangle((0, 0), 1, 1)]
|
|
216
|
+
label: list[str | None] = [self.label]
|
|
217
|
+
|
|
218
|
+
handler: dict[Rectangle, HandlerColormap] = {handle[0]: self.handler_colormap}
|
|
219
|
+
return handle, label, handler
|
|
220
|
+
|
|
221
|
+
@staticmethod
|
|
222
|
+
def create_unique_class_with_handler(base_class, handler, class_name=None):
|
|
223
|
+
"""
|
|
224
|
+
Create a unique class that extends a given base class and associates it with a custom handler.
|
|
225
|
+
|
|
226
|
+
Parameters
|
|
227
|
+
--------------------
|
|
228
|
+
base_class : type
|
|
229
|
+
The base class to extend.
|
|
230
|
+
handler : HandlerBase
|
|
231
|
+
The custom handler to associate with the new class.
|
|
232
|
+
class_name : str, optional
|
|
233
|
+
Name for the newly created class. If not provided, a unique name is generated.
|
|
234
|
+
|
|
235
|
+
Returns
|
|
236
|
+
--------------------
|
|
237
|
+
type
|
|
238
|
+
A new class that extends the base class and is associated with the custom handler.
|
|
239
|
+
|
|
240
|
+
Examples
|
|
241
|
+
--------------------
|
|
242
|
+
>>> from matplotlib.patches import Rectangle
|
|
243
|
+
>>> from matplotlib.legend_handler import HandlerBase
|
|
244
|
+
>>> class CustomHandler(HandlerBase):
|
|
245
|
+
... pass
|
|
246
|
+
>>> custom_handler = CustomHandler()
|
|
247
|
+
>>> NewRectangle = LegendColormap.create_unique_class_with_handler(Rectangle, custom_handler)
|
|
248
|
+
>>> new_instance = NewRectangle((0, 0), 1, 1)
|
|
249
|
+
>>> print(type(new_instance).__name__)
|
|
250
|
+
CustomRectangle_<unique_id>
|
|
251
|
+
"""
|
|
252
|
+
# Create Unique Class
|
|
253
|
+
if class_name is None:
|
|
254
|
+
class_name = f"Custom{base_class.__name__}_{id(handler)}"
|
|
255
|
+
|
|
256
|
+
# Create a new class with the given handler
|
|
257
|
+
UniqueClass = type(class_name, (base_class,), {})
|
|
258
|
+
return UniqueClass
|
|
259
|
+
|
|
260
|
+
def axis_patch(self):
|
|
261
|
+
"""
|
|
262
|
+
Add a dummy patch to the axis to represent the colormap legend.
|
|
263
|
+
|
|
264
|
+
Notes
|
|
265
|
+
--------------------
|
|
266
|
+
This method creates a dummy patch using a custom class associated with a colormap handler.
|
|
267
|
+
The patch is invisible but serves as a proxy for the colormap legend entry.
|
|
268
|
+
|
|
269
|
+
Examples
|
|
270
|
+
--------------------
|
|
271
|
+
>>> from matplotlib import pyplot as plt
|
|
272
|
+
>>> fig, ax = plt.subplots()
|
|
273
|
+
>>> legend_colormap = LegendColormap(0, cmap="viridis", label="Colormap")
|
|
274
|
+
>>> legend_colormap.axis_patch()
|
|
275
|
+
>>> plt.show()
|
|
276
|
+
"""
|
|
277
|
+
UniqueClass = self.create_unique_class_with_handler(
|
|
278
|
+
Rectangle, self.handler_colormap
|
|
279
|
+
)
|
|
280
|
+
cmap_dummy_handle = UniqueClass((0, 0), 0, 0, label=self.label, visible=False)
|
|
281
|
+
self.axis.add_patch(cmap_dummy_handle)
|
|
282
|
+
Lg.update_default_handler_map({cmap_dummy_handle: self.handler_colormap})
|
|
283
|
+
self.axis.legend(handles=[cmap_dummy_handle], labels=[self.label])
|
|
284
|
+
|
|
285
|
+
def legend_colormap(self) -> Lg:
|
|
286
|
+
"""
|
|
287
|
+
Create and display a colormap legend on the target axis.
|
|
288
|
+
|
|
289
|
+
Returns
|
|
290
|
+
--------------------
|
|
291
|
+
matplotlib.legend.Legend
|
|
292
|
+
The created legend object.
|
|
293
|
+
|
|
294
|
+
Notes
|
|
295
|
+
--------------------
|
|
296
|
+
This method builds on `axis_patch` to construct and render the legend.
|
|
297
|
+
|
|
298
|
+
Examples
|
|
299
|
+
--------------------
|
|
300
|
+
>>> from matplotlib import pyplot as plt
|
|
301
|
+
>>> fig, ax = plt.subplots()
|
|
302
|
+
>>> legend_colormap = LegendColormap(0, cmap="viridis", label="Color Legend")
|
|
303
|
+
>>> legend_colormap.legend_colormap()
|
|
304
|
+
>>> plt.show()
|
|
305
|
+
"""
|
|
306
|
+
self.axis_patch()
|
|
307
|
+
return self.axis.legend()
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
@bind_passed_params()
|
|
311
|
+
def legend_colormap(
|
|
312
|
+
axis_target: int | Axes,
|
|
313
|
+
cmap: str = "viridis",
|
|
314
|
+
label: str | None = None,
|
|
315
|
+
num_stripes: int = 8,
|
|
316
|
+
vmin: int | float = 0,
|
|
317
|
+
vmax: int | float = 1,
|
|
318
|
+
reverse: bool = False,
|
|
319
|
+
**kwargs: Any,
|
|
320
|
+
) -> Lg:
|
|
321
|
+
"""
|
|
322
|
+
Create and display a colormap legend on a specified axis.
|
|
323
|
+
|
|
324
|
+
Parameters
|
|
325
|
+
--------------------
|
|
326
|
+
axis_target : int | Axes
|
|
327
|
+
The target axis for the legend. Can be an axis index or an `Axes` object.
|
|
328
|
+
cmap : str, optional
|
|
329
|
+
The colormap to use for the legend (default is 'viridis').
|
|
330
|
+
label : str | None, optional
|
|
331
|
+
The label to display for the colormap in the legend (default is None).
|
|
332
|
+
num_stripes : int, optional
|
|
333
|
+
The number of stripes to divide the colormap into (default is 8).
|
|
334
|
+
vmin : int | float, optional
|
|
335
|
+
The minimum value of the colormap (default is 0).
|
|
336
|
+
vmax : int | float, optional
|
|
337
|
+
The maximum value of the colormap (default is 1).
|
|
338
|
+
reverse : bool, optional
|
|
339
|
+
Whether to reverse the colormap (default is False).
|
|
340
|
+
**kwargs : Any
|
|
341
|
+
Additional keyword arguments for configuring the legend.
|
|
342
|
+
|
|
343
|
+
Returns
|
|
344
|
+
--------------------
|
|
345
|
+
matplotlib.legend.Legend
|
|
346
|
+
The created legend object.
|
|
347
|
+
|
|
348
|
+
Notes
|
|
349
|
+
--------------------
|
|
350
|
+
This function binds passed parameters and creates a `LegendColormap` instance
|
|
351
|
+
to generate a colormap legend on the specified axis.
|
|
352
|
+
|
|
353
|
+
Examples
|
|
354
|
+
--------------------
|
|
355
|
+
>>> import gsplot as gs
|
|
356
|
+
>>> gs.legend_colormap(
|
|
357
|
+
... axis_target=0,
|
|
358
|
+
... cmap="plasma",
|
|
359
|
+
... label="Example Legend",
|
|
360
|
+
... num_stripes=10,
|
|
361
|
+
... vmin=0,
|
|
362
|
+
... vmax=100,
|
|
363
|
+
... reverse=True,
|
|
364
|
+
... )
|
|
365
|
+
"""
|
|
366
|
+
|
|
367
|
+
passed_params: dict[str, Any] = ParamsGetter("passed_params").get_bound_params()
|
|
368
|
+
class_params = CreateClassParams(passed_params).get_class_params()
|
|
369
|
+
|
|
370
|
+
_legend_colormap = LegendColormap(
|
|
371
|
+
class_params["axis_target"],
|
|
372
|
+
class_params["cmap"],
|
|
373
|
+
class_params["label"],
|
|
374
|
+
class_params["num_stripes"],
|
|
375
|
+
class_params["vmin"],
|
|
376
|
+
class_params["vmax"],
|
|
377
|
+
class_params["reverse"],
|
|
378
|
+
**class_params["kwargs"],
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
return _legend_colormap.legend_colormap()
|
gsplot/style/ticks.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
import matplotlib.pyplot as plt
|
|
4
|
+
import matplotlib.ticker as plticker
|
|
5
|
+
from matplotlib.axes import Axes
|
|
6
|
+
from matplotlib.ticker import NullLocator
|
|
7
|
+
|
|
8
|
+
from ..figure.axes_base import AxesResolver
|
|
9
|
+
|
|
10
|
+
__all__: list[str] = ["ticks_off", "ticks_on", "ticks_on_axes"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class MinorTicks:
|
|
14
|
+
"""
|
|
15
|
+
A class for managing minor ticks on a specific axis.
|
|
16
|
+
|
|
17
|
+
Parameters
|
|
18
|
+
--------------------
|
|
19
|
+
axis_target : int | Axes
|
|
20
|
+
The target axis for minor tick configuration. Can be an axis index or an `Axes` object.
|
|
21
|
+
|
|
22
|
+
Methods
|
|
23
|
+
--------------------
|
|
24
|
+
set_minor_ticks_off(mode)
|
|
25
|
+
Turns off minor ticks on the specified axis.
|
|
26
|
+
set_minor_ticks_on(mode)
|
|
27
|
+
Turns on minor ticks on the specified axis.
|
|
28
|
+
|
|
29
|
+
Examples
|
|
30
|
+
--------------------
|
|
31
|
+
>>> import matplotlib.pyplot as plt
|
|
32
|
+
>>> fig, ax = plt.subplots()
|
|
33
|
+
>>> x = [0, 1, 2, 3, 4]
|
|
34
|
+
>>> y = [0, 1, 4, 9, 16]
|
|
35
|
+
>>> ax.plot(x, y)
|
|
36
|
+
>>> # Turn off minor ticks on the x-axis
|
|
37
|
+
>>> ticks_off(axis_target=ax, mode="x")
|
|
38
|
+
>>> # Turn on minor ticks on the y-axis
|
|
39
|
+
>>> ticks_on(axis_target=ax, mode="y")
|
|
40
|
+
>>> plt.show()
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(self, axis_target: int | Axes) -> None:
|
|
44
|
+
self.axis_target: int | Axes = axis_target
|
|
45
|
+
|
|
46
|
+
_axes_resolver = AxesResolver(axis_target)
|
|
47
|
+
self.axis_index: int = _axes_resolver.axis_index
|
|
48
|
+
self.axis: Axes = _axes_resolver.axis
|
|
49
|
+
|
|
50
|
+
def set_minor_ticks_off(self, mode=Literal["x", "y", "xy"]) -> None:
|
|
51
|
+
"""
|
|
52
|
+
Turn off minor ticks for the specified axis.
|
|
53
|
+
|
|
54
|
+
Parameters
|
|
55
|
+
--------------------
|
|
56
|
+
mode : Literal["x", "y", "xy"], optional
|
|
57
|
+
Specifies the axis to configure. 'x' for x-axis, 'y' for y-axis,
|
|
58
|
+
and 'xy' for both axes. Default is 'xy'.
|
|
59
|
+
"""
|
|
60
|
+
if mode == "x":
|
|
61
|
+
self.axis.xaxis.set_minor_locator(NullLocator())
|
|
62
|
+
elif mode == "y":
|
|
63
|
+
self.axis.yaxis.set_minor_locator(NullLocator())
|
|
64
|
+
elif mode == "xy":
|
|
65
|
+
self.axis.xaxis.set_minor_locator(NullLocator())
|
|
66
|
+
self.axis.yaxis.set_minor_locator(NullLocator())
|
|
67
|
+
else:
|
|
68
|
+
raise ValueError("Invalid mode. Choose from 'x', 'y', or 'xy'.")
|
|
69
|
+
|
|
70
|
+
def set_minor_ticks_on(self, mode=Literal["x", "y", "xy"]) -> None:
|
|
71
|
+
"""
|
|
72
|
+
Turn on minor ticks for the specified axis.
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
--------------------
|
|
76
|
+
mode : Literal["x", "y", "xy"], optional
|
|
77
|
+
Specifies the axis to configure. 'x' for x-axis, 'y' for y-axis,
|
|
78
|
+
and 'xy' for both axes. Default is 'xy'.
|
|
79
|
+
"""
|
|
80
|
+
if mode == "x":
|
|
81
|
+
self.axis.xaxis.set_minor_locator(plticker.AutoMinorLocator())
|
|
82
|
+
elif mode == "y":
|
|
83
|
+
self.axis.yaxis.set_minor_locator(plticker.AutoMinorLocator())
|
|
84
|
+
elif mode == "xy":
|
|
85
|
+
self.axis.xaxis.set_minor_locator(plticker.AutoMinorLocator())
|
|
86
|
+
self.axis.yaxis.set_minor_locator(plticker.AutoMinorLocator())
|
|
87
|
+
else:
|
|
88
|
+
raise ValueError("Invalid mode. Choose from 'x', 'y', or 'xy'.")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class MinorTicksAxes:
|
|
92
|
+
"""
|
|
93
|
+
A class for managing minor ticks across all axes in the current figure.
|
|
94
|
+
|
|
95
|
+
Methods
|
|
96
|
+
--------------------
|
|
97
|
+
set_minor_ticks_axes()
|
|
98
|
+
Turn on minor ticks for all axes in the current figure.
|
|
99
|
+
|
|
100
|
+
Examples
|
|
101
|
+
--------------------
|
|
102
|
+
>>> # Turn on minor ticks for all axes
|
|
103
|
+
>>> ticks_on_axes()
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
def set_minor_ticks_axes(self) -> None:
|
|
107
|
+
"""
|
|
108
|
+
Turn on minor ticks for all axes in the current figure.
|
|
109
|
+
"""
|
|
110
|
+
for axis in plt.gcf().axes:
|
|
111
|
+
axis.xaxis.set_minor_locator(plticker.AutoMinorLocator())
|
|
112
|
+
axis.yaxis.set_minor_locator(plticker.AutoMinorLocator())
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def ticks_off(axis_target: int | Axes, mode=Literal["x", "y", "xy"]) -> None:
|
|
116
|
+
"""
|
|
117
|
+
Turn off minor ticks for the specified axis.
|
|
118
|
+
|
|
119
|
+
Parameters
|
|
120
|
+
--------------------
|
|
121
|
+
axis_target : int | Axes
|
|
122
|
+
The target axis for minor tick configuration.
|
|
123
|
+
mode : Literal["x", "y", "xy"], optional
|
|
124
|
+
Specifies the axis to configure. 'x' for x-axis, 'y' for y-axis,
|
|
125
|
+
and 'xy' for both axes. Default is 'xy'.
|
|
126
|
+
|
|
127
|
+
Examples
|
|
128
|
+
--------------------
|
|
129
|
+
>>> import gsplot as gs
|
|
130
|
+
>>> # Turn off minor ticks on the x-axis
|
|
131
|
+
>>> gs.ticks_off(axis_target=ax, mode="x")
|
|
132
|
+
"""
|
|
133
|
+
MinorTicks(axis_target).set_minor_ticks_off(mode)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def ticks_on(axis_target: int | Axes, mode=Literal["x", "y", "xy"]) -> None:
|
|
137
|
+
"""
|
|
138
|
+
Turn on minor ticks for the specified axis.
|
|
139
|
+
|
|
140
|
+
Parameters
|
|
141
|
+
--------------------
|
|
142
|
+
axis_target : int | Axes
|
|
143
|
+
The target axis for minor tick configuration.
|
|
144
|
+
mode : Literal["x", "y", "xy"], optional
|
|
145
|
+
Specifies the axis to configure. 'x' for x-axis, 'y' for y-axis,
|
|
146
|
+
and 'xy' for both axes. Default is 'xy'.
|
|
147
|
+
|
|
148
|
+
Examples
|
|
149
|
+
--------------------
|
|
150
|
+
>>> import gsplot as gs
|
|
151
|
+
>>> # Turn on minor ticks on the x-axis
|
|
152
|
+
>>> gs.ticks_on(axis_target=ax, mode="x")
|
|
153
|
+
"""
|
|
154
|
+
MinorTicks(axis_target).set_minor_ticks_on(mode)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def ticks_on_axes() -> None:
|
|
158
|
+
"""
|
|
159
|
+
Turn on minor ticks for all axes in the current figure.
|
|
160
|
+
|
|
161
|
+
Examples
|
|
162
|
+
--------------------
|
|
163
|
+
>>> import gsplot as gs
|
|
164
|
+
>>> # Turn on minor ticks for all axes
|
|
165
|
+
>>> gs.ticks_on_axes()
|
|
166
|
+
"""
|
|
167
|
+
MinorTicksAxes().set_minor_ticks_axes()
|
gsplot/version.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Soichiro Yamane
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: gsplot
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: General-scientific plot based on matplotlib
|
|
5
|
+
Author: Giordano Mattoni
|
|
6
|
+
Author-email: mattoni@scphys.kyoto-u.ac.jp
|
|
7
|
+
Requires-Python: >=3.10,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Requires-Dist: matplotlib (>=3.9.0,<4.0.0)
|
|
14
|
+
Requires-Dist: numpy (>=1.26.4,<2.0.0)
|
|
15
|
+
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
|
16
|
+
Requires-Dist: rich (>=13.9.4,<14.0.0)
|
|
17
|
+
Requires-Dist: types-pyyaml (>=6.0.12.20240917,<7.0.0.0)
|
|
18
|
+
Project-URL: Homepage, https://soichiroyamane.github.io/gsplot/
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# gsplot 📈
|
|
22
|
+
|
|
23
|
+
<div align="center">
|
|
24
|
+
<img src="docs/_static/logo_gsplot.svg" alt="logo_gsplot" width="100">
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
[](https://github.com/SoichiroYamane/gsplot/actions/workflows/gh-pages-sphinx.yml)
|
|
28
|
+

|
|
29
|
+

|
|
30
|
+
----------------
|
|
31
|
+
|
|
32
|
+
<p align="center" style="font-weight: bold; font-size: 1.2em; margin: 20px 0;">
|
|
33
|
+
<a href="https://soichiroyamane.github.io/gsplot/" style="text-decoration: none;">Docs</a> |
|
|
34
|
+
<a href="#authors" style="text-decoration: none;">Authors</a> |
|
|
35
|
+
<a href="#license" style="text-decoration: none;">License</a>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
Welcome to **gsplot** (general-scientific plot), a toolkit designed to enhance the capabilities of data visualization based on [matplotlib](https://matplotlib.org). This package is specifically tailored for creating high-quality figures aimed at the scientific field.
|
|
39
|
+
|
|
40
|
+
## Features ✨
|
|
41
|
+
|
|
42
|
+
- **Better Plot, Less Code**: Simplify the process of creating high-quality figures 💤
|
|
43
|
+
- **Compatibility**: Compatible with [matplotlib](https://matplotlib.org) 📊
|
|
44
|
+
- **Customization**: Customize your configuration to fit your needs 🎨
|
|
45
|
+
- **Reproducibility**: Save your package status to make plots reproducible 📦
|
|
46
|
+
|
|
47
|
+
### Example using gsplot 📈
|
|
48
|
+
|
|
49
|
+
[See more details](https://soichiroyamane.github.io/gsplot/guides/demo/4_paper_plot.html)
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
### Example with Python REPL 🐍 and neovim 🌟
|
|
54
|
+
|
|
55
|
+
[See more details](https://soichiroyamane.github.io/gsplot/guides/demo/13_REPL.html)
|
|
56
|
+

|
|
57
|
+
|
|
58
|
+
## Getting Started 🚀
|
|
59
|
+
|
|
60
|
+
### Installation
|
|
61
|
+
|
|
62
|
+
To use **gsplot**, ensure that you have `Python 3.10+` installed. You can install the package using `pip`:
|
|
63
|
+
|
|
64
|
+
#### important
|
|
65
|
+
|
|
66
|
+
**⚠️ This package has not been published yet**
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install gsplot
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Authors 👥
|
|
73
|
+
|
|
74
|
+
This repository was forked from codes developed by Giordano Mattoni.
|
|
75
|
+
|
|
76
|
+
- Giordano Mattoni
|
|
77
|
+
- Soichiro Yamane
|
|
78
|
+
|
|
79
|
+
## License 📜
|
|
80
|
+
|
|
81
|
+
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
|
|
82
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
gsplot/__init__.py,sha256=7FBZoRDULDAcWdD-XsQ_iyVrLQZ-WDx8SZUKosz33Dw,3342
|
|
2
|
+
gsplot/base/base.py,sha256=hzI-FmLNXKRNqno624G3WVOEE-Yn7qV4ZRmMshlCNgw,16652
|
|
3
|
+
gsplot/base/base_alias_validator.py,sha256=TbRGiUPEoYdjwMaM5752seKFGI32PEV2sTYBiAO4tnk,5730
|
|
4
|
+
gsplot/color/colormap.py,sha256=KEdDNKjJ48Jy637rpEYZzLLs24n2Zv17scNI62ZwDro,7197
|
|
5
|
+
gsplot/config/config.py,sha256=ZTtm4ftjf4TAvQsvGUWSp5UCWZSofN6gW1Jt1ISl9VM,13376
|
|
6
|
+
gsplot/data/load_file.py,sha256=vtCd4WoI2J5C1Gdql-POzB8lUwHlUOv0ogTdcQ4d2r0,6440
|
|
7
|
+
gsplot/figure/axes.py,sha256=ejPMmBHwUrxBCYX4E2UETSPzuCsSzXd09n2ECkQhiMc,11679
|
|
8
|
+
gsplot/figure/axes_base.py,sha256=u926PgjjgoXqLByxIWVMGwmHWTayLu5yiusSgKUK8pI,30086
|
|
9
|
+
gsplot/figure/figure_tools.py,sha256=xKU60GbsoaOvorbHzTGMbTppaELvksxBgf3xuSz0YCI,1832
|
|
10
|
+
gsplot/figure/show.py,sha256=_eBL_VtGWelCAwfT3Pn7bW5ljCWAFWuVggkPVTHt_fc,6311
|
|
11
|
+
gsplot/figure/store.py,sha256=cVhuPE6EMxex7Uiewm5FInBMhAsyEytj746MGXSLasI,3306
|
|
12
|
+
gsplot/hello_world/hello_world.py,sha256=DOQ8qD3WYaCiZeU8uQf2IvDQb8-Jx4FhTdI5tuJ79is,1108
|
|
13
|
+
gsplot/logger.py,sha256=nn2DOVznk4NSyrRBKlBeRbJT692-ff7Mqga1TDWRqPE,4681
|
|
14
|
+
gsplot/path/path.py,sha256=vkmT2gfiS73-0tcH05mMNClNT24g_EZe3WqgoxBuUrY,6462
|
|
15
|
+
gsplot/plot/line.py,sha256=iX4JkHdNTbJ8_BzESGXBR4QTJitLK-oK9WutMlZyyc8,11429
|
|
16
|
+
gsplot/plot/line_base.py,sha256=pjuOoNCDwip9X1c9TGA2PtnoQLcpMIrbtP1bi03byz8,8236
|
|
17
|
+
gsplot/plot/line_colormap_base.py,sha256=uzUOyPLPzMaVTVcsv3NuHNQBfbv_vUovcnEWtOZkRl4,4800
|
|
18
|
+
gsplot/plot/line_colormap_dashed.py,sha256=g7Mm82WnWiUhQ6IGk6YeNynpuc9R8H97vdWO2-lkvYY,19061
|
|
19
|
+
gsplot/plot/line_colormap_solid.py,sha256=U6r_I1jEuM96qUWiDnK5yK-mhBLtu3_DdxtMFAD9DRM,10004
|
|
20
|
+
gsplot/plot/scatter.py,sha256=13aG4OkfBQM-g1elODPLtMkfW_q-CivEsgxTfoQ3XoA,7542
|
|
21
|
+
gsplot/plot/scatter_colormap.py,sha256=7CXQxpOsoar6bjxCgAKFoMTYoYq1X9y1FiJdOHxJzO0,10098
|
|
22
|
+
gsplot/style/graph.py,sha256=v2Of4l3YClxb-RkUatudT8XKu-bxpdu4NNYmnTkUc90,13206
|
|
23
|
+
gsplot/style/label.py,sha256=SIjfhQGsACrXNyNHF2pKAZLKbX94AreeVBHbpteLMqI,27304
|
|
24
|
+
gsplot/style/legend.py,sha256=tthBqoKJAScF64TgnHosyuHL_RH5iAo6iy3JVcZy1IY,14317
|
|
25
|
+
gsplot/style/legend_colormap.py,sha256=K0GaDiVY4Ni9_QyFJ235xYgr9o7sTuYn2Li8AnAEpxY,12218
|
|
26
|
+
gsplot/style/ticks.py,sha256=AOPsRcIWivyfsPPK6RFeowyxOxs_h5sCDqHIpFgHKlY,5270
|
|
27
|
+
gsplot/version.py,sha256=HA7iQdnEAhfkpsnRnvrMupt58dBFaceIOiu-aBPH-_A,78
|
|
28
|
+
gsplot-0.0.1.dist-info/LICENSE,sha256=L0-evhREqD09CCQRPCb6fdSylIwxzL-UMtM5h6fFAT4,1072
|
|
29
|
+
gsplot-0.0.1.dist-info/METADATA,sha256=KsvyJ5-ZzdVeDNWv7mEH3rcMV0l9EjJrR7-ZUl6CH78,2997
|
|
30
|
+
gsplot-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
31
|
+
gsplot-0.0.1.dist-info/RECORD,,
|