gsplot 0.1.0__tar.gz → 0.1.2__tar.gz
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-0.1.0 → gsplot-0.1.2}/PKG-INFO +9 -8
- {gsplot-0.1.0 → gsplot-0.1.2}/README.md +8 -7
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/__init__.py +4 -0
- gsplot-0.1.2/gsplot/figure/axes_inset.py +708 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/style/label.py +137 -43
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/style/legend.py +5 -2
- gsplot-0.1.2/gsplot/version.py +2 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/pyproject.toml +1 -1
- gsplot-0.1.0/gsplot/version.py +0 -2
- {gsplot-0.1.0 → gsplot-0.1.2}/LICENSE +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/base/base.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/base/base_alias_validator.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/color/colormap.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/config/config.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/data/load_file.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/figure/axes.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/figure/axes_base.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/figure/axes_range_base.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/figure/figure_tools.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/figure/show.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/figure/store.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/hello_world/hello_world.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/logger.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/path/path.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/plot/line.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/plot/line_base.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/plot/line_colormap_base.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/plot/line_colormap_dashed.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/plot/line_colormap_solid.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/plot/scatter.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/plot/scatter_colormap.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/style/graph.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/style/legend_colormap.py +0 -0
- {gsplot-0.1.0 → gsplot-0.1.2}/gsplot/style/ticks.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gsplot
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: General-scientific plot based on matplotlib
|
|
5
5
|
Author: Giordano Mattoni
|
|
6
6
|
Author-email: mattoni@scphys.kyoto-u.ac.jp
|
|
@@ -26,6 +26,7 @@ Description-Content-Type: text/markdown
|
|
|
26
26
|

|
|
27
27
|

|
|
28
28
|

|
|
29
|
+
[](https://pepy.tech/projects/gsplot)
|
|
29
30
|

|
|
30
31
|

|
|
31
32
|
|
|
@@ -37,21 +38,21 @@ Description-Content-Type: text/markdown
|
|
|
37
38
|
<a href="#license" style="text-decoration: none;">License</a>
|
|
38
39
|
</p>
|
|
39
40
|
|
|
40
|
-
Welcome to **gsplot** (
|
|
41
|
+
Welcome to **gsplot** (General-Scientific Plot), a toolkit designed to elevate 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.
|
|
41
42
|
|
|
42
43
|
> [!WARNING]
|
|
43
44
|
> This package is _beta_ quality. Expect breaking changes and many bugs 🐛. Please report any issue you encounter 🤝.
|
|
44
45
|
|
|
45
46
|
## ✨ Features
|
|
46
47
|
|
|
47
|
-
- **Better Plot, Less
|
|
48
|
-
- **Compatibility**:
|
|
49
|
-
- **Customization**:
|
|
50
|
-
- **Reproducibility**: Save
|
|
48
|
+
- **Better Plot, Less Effort**: Effortlessly create high-quality figures ⚛️
|
|
49
|
+
- **Compatibility**: Fully compatible with [matplotlib](https://matplotlib.org) 📊
|
|
50
|
+
- **Customization**: Tailor configurations to suit your needs 🎨
|
|
51
|
+
- **Reproducibility**: Save package states for reproducible plots 📦
|
|
51
52
|
|
|
52
53
|
### 📈 Example using gsplot
|
|
53
54
|
|
|
54
|
-
[See more details](https://soichiroyamane.github.io/gsplot/guides/
|
|
55
|
+
[See more details](https://soichiroyamane.github.io/gsplot/stable/guides/demo/4_paper_plot.html)
|
|
55
56
|
|
|
56
57
|

|
|
57
58
|
|
|
@@ -59,7 +60,7 @@ Welcome to **gsplot** (general-scientific plot), a toolkit designed to enhance t
|
|
|
59
60
|
|
|
60
61
|
[See more details](https://soichiroyamane.github.io/gsplot/stable/guides/demo/13_REPL.html)
|
|
61
62
|
|
|
62
|
-

|
|
63
64
|
|
|
64
65
|
## 🚀 Getting Started
|
|
65
66
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|

|
|
7
7
|

|
|
8
8
|

|
|
9
|
+
[](https://pepy.tech/projects/gsplot)
|
|
9
10
|

|
|
10
11
|

|
|
11
12
|
|
|
@@ -17,21 +18,21 @@
|
|
|
17
18
|
<a href="#license" style="text-decoration: none;">License</a>
|
|
18
19
|
</p>
|
|
19
20
|
|
|
20
|
-
Welcome to **gsplot** (
|
|
21
|
+
Welcome to **gsplot** (General-Scientific Plot), a toolkit designed to elevate 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.
|
|
21
22
|
|
|
22
23
|
> [!WARNING]
|
|
23
24
|
> This package is _beta_ quality. Expect breaking changes and many bugs 🐛. Please report any issue you encounter 🤝.
|
|
24
25
|
|
|
25
26
|
## ✨ Features
|
|
26
27
|
|
|
27
|
-
- **Better Plot, Less
|
|
28
|
-
- **Compatibility**:
|
|
29
|
-
- **Customization**:
|
|
30
|
-
- **Reproducibility**: Save
|
|
28
|
+
- **Better Plot, Less Effort**: Effortlessly create high-quality figures ⚛️
|
|
29
|
+
- **Compatibility**: Fully compatible with [matplotlib](https://matplotlib.org) 📊
|
|
30
|
+
- **Customization**: Tailor configurations to suit your needs 🎨
|
|
31
|
+
- **Reproducibility**: Save package states for reproducible plots 📦
|
|
31
32
|
|
|
32
33
|
### 📈 Example using gsplot
|
|
33
34
|
|
|
34
|
-
[See more details](https://soichiroyamane.github.io/gsplot/guides/
|
|
35
|
+
[See more details](https://soichiroyamane.github.io/gsplot/stable/guides/demo/4_paper_plot.html)
|
|
35
36
|
|
|
36
37
|

|
|
37
38
|
|
|
@@ -39,7 +40,7 @@ Welcome to **gsplot** (general-scientific plot), a toolkit designed to enhance t
|
|
|
39
40
|
|
|
40
41
|
[See more details](https://soichiroyamane.github.io/gsplot/stable/guides/demo/13_REPL.html)
|
|
41
42
|
|
|
42
|
-

|
|
43
44
|
|
|
44
45
|
## 🚀 Getting Started
|
|
45
46
|
|
|
@@ -3,6 +3,7 @@ from .config.config import (Config, config_dict, config_entry_option,
|
|
|
3
3
|
config_load, save_metadata)
|
|
4
4
|
from .data.load_file import load_file
|
|
5
5
|
from .figure.axes import axes
|
|
6
|
+
from .figure.axes_inset import axes_inset, axes_inset_padding
|
|
6
7
|
from .figure.figure_tools import get_figure_size
|
|
7
8
|
from .figure.show import show
|
|
8
9
|
from .hello_world.hello_world import hello_world
|
|
@@ -49,6 +50,9 @@ __all__ = [
|
|
|
49
50
|
"load_file",
|
|
50
51
|
# figure/axes.py
|
|
51
52
|
"axes",
|
|
53
|
+
# figure/axes_inset.py
|
|
54
|
+
"axes_inset",
|
|
55
|
+
"axes_inset_padding",
|
|
52
56
|
# figure/figure_tools.py
|
|
53
57
|
"get_figure_size",
|
|
54
58
|
# figure/show.py
|
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
from typing import Any, cast
|
|
2
|
+
|
|
3
|
+
from matplotlib.axes import Axes
|
|
4
|
+
from matplotlib.transforms import BboxBase, Transform, TransformedBbox
|
|
5
|
+
from matplotlib.typing import ColorType
|
|
6
|
+
from mpl_toolkits.axes_grid1.inset_locator import (BboxConnector, BboxPatch,
|
|
7
|
+
inset_axes)
|
|
8
|
+
|
|
9
|
+
from ..base.base import CreateClassParams, ParamsGetter, bind_passed_params
|
|
10
|
+
from ..style.label import Label
|
|
11
|
+
from ..style.ticks import MinorTicks
|
|
12
|
+
|
|
13
|
+
__all__ = ["axes_inset", "axes_inset_padding"]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class InsetAxesBase:
|
|
17
|
+
"""
|
|
18
|
+
A utility class for managing inset axes in a Matplotlib figure.
|
|
19
|
+
|
|
20
|
+
This class provides functionality for configuring and customizing inset axes,
|
|
21
|
+
including zooming, labeling, and enabling minor ticks. It also allows for manual
|
|
22
|
+
control of zoom connectors and axis limits.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
--------------------
|
|
26
|
+
ax : Axes
|
|
27
|
+
The main axis in the figure.
|
|
28
|
+
axins : Axes
|
|
29
|
+
The inset axis in the figure.
|
|
30
|
+
lab_lims : list[Any] | None, optional
|
|
31
|
+
List specifying axis labels and limits for the inset axis.
|
|
32
|
+
Expected format: [x_label, y_label, x_lim_min, x_lim_max, y_lim_min, y_lim_max].
|
|
33
|
+
minor_ticks : bool, default=True
|
|
34
|
+
Whether to enable minor ticks on the inset axis.
|
|
35
|
+
zoom : bool or tuple[tuple[int, int], tuple[int, int]], default=True
|
|
36
|
+
Zoom settings for the inset axis.
|
|
37
|
+
- If True, uses the built-in zoom indication.
|
|
38
|
+
- If a tuple, manually connects the axes with zoom connectors.
|
|
39
|
+
zoom_color : ColorType, default='black'
|
|
40
|
+
Color for the zoom connectors and patches.
|
|
41
|
+
zoom_alpha : int | float, default=0.3
|
|
42
|
+
Transparency for the zoom connectors and patches.
|
|
43
|
+
**kwargs : Any
|
|
44
|
+
Additional keyword arguments for axis label configuration.
|
|
45
|
+
|
|
46
|
+
Notes
|
|
47
|
+
--------------------
|
|
48
|
+
This class is designed for cases where inset axes are needed for enhanced
|
|
49
|
+
visualization. It uses helper classes like `Label` and `MinorTicks` to
|
|
50
|
+
streamline customization.
|
|
51
|
+
|
|
52
|
+
Methods
|
|
53
|
+
--------------------
|
|
54
|
+
manual_inset_zoom():
|
|
55
|
+
Manually connect the main axis to the inset axis with zoom connectors.
|
|
56
|
+
|
|
57
|
+
indicate_inset_zoom():
|
|
58
|
+
Use the built-in Matplotlib method to indicate zoom on the inset axis.
|
|
59
|
+
|
|
60
|
+
inset_zoom():
|
|
61
|
+
Automatically apply zoom connectors based on the `zoom` attribute.
|
|
62
|
+
|
|
63
|
+
set_minor_ticks():
|
|
64
|
+
Enable minor ticks on the inset axis.
|
|
65
|
+
|
|
66
|
+
label():
|
|
67
|
+
Configure and set labels and axis limits for the inset axis.
|
|
68
|
+
|
|
69
|
+
Warnings
|
|
70
|
+
--------------------
|
|
71
|
+
- Ensure that `lab_lims` is provided and correctly formatted when calling `label()`.
|
|
72
|
+
- `zoom` should be a tuple of tuples when using `manual_inset_zoom()`.
|
|
73
|
+
|
|
74
|
+
Examples
|
|
75
|
+
--------------------
|
|
76
|
+
>>> import matplotlib.pyplot as plt
|
|
77
|
+
>>> fig, ax = plt.subplots()
|
|
78
|
+
>>> axins = ax.inset_axes([0.5, 0.5, 0.4, 0.4])
|
|
79
|
+
>>> inset = InsetAxesBase(
|
|
80
|
+
... ax,
|
|
81
|
+
... axins,
|
|
82
|
+
... lab_lims=["X Label", "Y Label", 0, 1, 0, 1],
|
|
83
|
+
... zoom=((1, 2), (3, 4)),
|
|
84
|
+
... )
|
|
85
|
+
>>> inset.set_minor_ticks()
|
|
86
|
+
>>> inset.label()
|
|
87
|
+
>>> inset.inset_zoom()
|
|
88
|
+
>>> plt.show()
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
def __init__(
|
|
92
|
+
self,
|
|
93
|
+
ax,
|
|
94
|
+
axins,
|
|
95
|
+
lab_lims: list[Any] | None = None,
|
|
96
|
+
minor_ticks: bool = True,
|
|
97
|
+
zoom: bool | tuple[tuple[int, int], tuple[int, int]] = True,
|
|
98
|
+
zoom_color: ColorType = "black",
|
|
99
|
+
zoom_alpha: int | float = 0.3,
|
|
100
|
+
**kwargs,
|
|
101
|
+
) -> None:
|
|
102
|
+
self.ax: Axes = ax
|
|
103
|
+
self.axins: Axes = axins
|
|
104
|
+
self.lab_lims: list[Any] | None = lab_lims
|
|
105
|
+
self.minor_ticks: bool = minor_ticks
|
|
106
|
+
self.zoom: bool | tuple[tuple[int, int], tuple[int, int]] = zoom
|
|
107
|
+
self.zoom_color: ColorType = zoom_color
|
|
108
|
+
self.zoom_alpha: int | float = zoom_alpha
|
|
109
|
+
self.kwargs: Any = kwargs
|
|
110
|
+
|
|
111
|
+
def manual_inset_zoom(self):
|
|
112
|
+
"""
|
|
113
|
+
Manually connect the main axis to the inset axis with zoom connectors.
|
|
114
|
+
|
|
115
|
+
This method adds connectors and a patch between the main and inset axes
|
|
116
|
+
to visually represent the zoomed-in region.
|
|
117
|
+
|
|
118
|
+
Raises:
|
|
119
|
+
ValueError: If `zoom` is not a tuple of tuples.
|
|
120
|
+
|
|
121
|
+
Notes
|
|
122
|
+
--------------------
|
|
123
|
+
This method is used when manual control over zoom connectors is required.
|
|
124
|
+
"""
|
|
125
|
+
if isinstance(self.zoom, bool):
|
|
126
|
+
raise ValueError("locs_zoom must be a tuple of tuples")
|
|
127
|
+
|
|
128
|
+
loc1a, loc1b = self.zoom[0]
|
|
129
|
+
loc2a, loc2b = self.zoom[1]
|
|
130
|
+
rect = TransformedBbox(self.axins.viewLim, self.ax.transData)
|
|
131
|
+
pp = BboxPatch(
|
|
132
|
+
rect, fill=False, edgecolor=self.zoom_color, alpha=self.zoom_alpha
|
|
133
|
+
)
|
|
134
|
+
self.ax.add_patch(pp)
|
|
135
|
+
p1 = BboxConnector(
|
|
136
|
+
self.axins.bbox,
|
|
137
|
+
rect,
|
|
138
|
+
loc1=loc1b,
|
|
139
|
+
loc2=loc1a,
|
|
140
|
+
color=self.zoom_color,
|
|
141
|
+
alpha=self.zoom_alpha,
|
|
142
|
+
)
|
|
143
|
+
self.axins.add_patch(p1)
|
|
144
|
+
p1.set_clip_on(False)
|
|
145
|
+
p2 = BboxConnector(
|
|
146
|
+
self.axins.bbox,
|
|
147
|
+
rect,
|
|
148
|
+
loc1=loc2b,
|
|
149
|
+
loc2=loc2a,
|
|
150
|
+
color=self.zoom_color,
|
|
151
|
+
alpha=self.zoom_alpha,
|
|
152
|
+
)
|
|
153
|
+
self.axins.add_patch(p2)
|
|
154
|
+
p2.set_clip_on(False)
|
|
155
|
+
|
|
156
|
+
def indicate_inset_zoom(self):
|
|
157
|
+
"""
|
|
158
|
+
Use Matplotlib's built-in method to indicate zoom on the inset axis.
|
|
159
|
+
|
|
160
|
+
This method creates a zoom indication using a rectangular outline between
|
|
161
|
+
the main and inset axes.
|
|
162
|
+
|
|
163
|
+
Notes
|
|
164
|
+
--------------------
|
|
165
|
+
This method is simpler and faster than `manual_inset_zoom` but offers
|
|
166
|
+
less customization.
|
|
167
|
+
"""
|
|
168
|
+
self.ax.indicate_inset_zoom(
|
|
169
|
+
self.axins, edgecolor=self.zoom_color, alpha=self.zoom_alpha
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
def inset_zoom(self):
|
|
173
|
+
"""
|
|
174
|
+
Apply zoom connectors to the inset axis based on the `zoom` attribute.
|
|
175
|
+
|
|
176
|
+
If `zoom` is True, the built-in zoom indication method is used.
|
|
177
|
+
If `zoom` is a tuple, manual zoom connectors are created using `manual_inset_zoom`.
|
|
178
|
+
|
|
179
|
+
Notes
|
|
180
|
+
--------------------
|
|
181
|
+
This method provides a unified interface for adding zoom connectors.
|
|
182
|
+
"""
|
|
183
|
+
if self.zoom is True:
|
|
184
|
+
self.indicate_inset_zoom()
|
|
185
|
+
elif isinstance(self.zoom, tuple):
|
|
186
|
+
self.manual_inset_zoom()
|
|
187
|
+
|
|
188
|
+
def set_minor_ticks(self):
|
|
189
|
+
"""
|
|
190
|
+
Enable minor ticks on the inset axis.
|
|
191
|
+
|
|
192
|
+
This method configures and displays minor ticks on both x and y axes
|
|
193
|
+
of the inset axis.
|
|
194
|
+
|
|
195
|
+
Notes
|
|
196
|
+
--------------------
|
|
197
|
+
Minor ticks enhance the readability of the inset axis.
|
|
198
|
+
"""
|
|
199
|
+
_minor_ticks = MinorTicks(self.axins)
|
|
200
|
+
_minor_ticks.set_minor_ticks_on(mode="xy")
|
|
201
|
+
|
|
202
|
+
def label(
|
|
203
|
+
self,
|
|
204
|
+
):
|
|
205
|
+
"""
|
|
206
|
+
Configure labels and axis limits for the inset axis.
|
|
207
|
+
|
|
208
|
+
This method sets the x and y axis labels and applies the specified
|
|
209
|
+
axis limits to the inset axis.
|
|
210
|
+
|
|
211
|
+
Raises:
|
|
212
|
+
ValueError: If `lab_lims` is not provided or has an invalid shape.
|
|
213
|
+
|
|
214
|
+
Notes
|
|
215
|
+
--------------------
|
|
216
|
+
This method utilizes the `Label` class to simplify axis labeling and limit configuration.
|
|
217
|
+
|
|
218
|
+
Examples
|
|
219
|
+
--------------------
|
|
220
|
+
>>> inset = InsetAxesBase(ax, axins, lab_lims=["X", "Y", 0, 1, 0, 1])
|
|
221
|
+
>>> inset.label()
|
|
222
|
+
"""
|
|
223
|
+
if not self.lab_lims:
|
|
224
|
+
raise ValueError("lab_lims must be provided")
|
|
225
|
+
|
|
226
|
+
_label = Label(
|
|
227
|
+
self.lab_lims,
|
|
228
|
+
minor_ticks_axes=False,
|
|
229
|
+
tight_layout=False,
|
|
230
|
+
**self.kwargs,
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
try:
|
|
234
|
+
x_lab, y_lab, *lims = self.lab_lims
|
|
235
|
+
except ValueError:
|
|
236
|
+
raise ValueError("lab_lims has invalid shape")
|
|
237
|
+
|
|
238
|
+
# Label the inset axes
|
|
239
|
+
_label.configure_axis_labels(self.axins, x_lab, y_lab, **self.kwargs)
|
|
240
|
+
# Set the axis limits
|
|
241
|
+
_label.configure_axis_limits(self.axins, lims)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class AxesInset:
|
|
245
|
+
"""
|
|
246
|
+
A class to create and manage inset axes in a Matplotlib figure.
|
|
247
|
+
|
|
248
|
+
This class simplifies the creation of inset axes, providing options for zooming,
|
|
249
|
+
labeling, minor ticks, and custom axis transformations.
|
|
250
|
+
|
|
251
|
+
Parameters
|
|
252
|
+
--------------------
|
|
253
|
+
ax : Axes
|
|
254
|
+
The main axis in the figure.
|
|
255
|
+
bounds : tuple[float, float, float, float]
|
|
256
|
+
Bounds for the inset axis in the format (x0, y0, width, height).
|
|
257
|
+
transform : Transform | None, optional
|
|
258
|
+
The transform to apply to the inset axis. Default is None.
|
|
259
|
+
projection : str | None, optional
|
|
260
|
+
The projection type for the inset axis. Default is None.
|
|
261
|
+
polar : bool, default=False
|
|
262
|
+
If True, the inset axis will use a polar projection.
|
|
263
|
+
lab_lims : list[Any] | None, optional
|
|
264
|
+
List specifying axis labels and limits for the inset axis.
|
|
265
|
+
Expected format: [x_label, y_label, x_lim_min, x_lim_max, y_lim_min, y_lim_max].
|
|
266
|
+
minor_ticks : bool, default=True
|
|
267
|
+
Whether to enable minor ticks on the inset axis.
|
|
268
|
+
zoom : bool or tuple[tuple[int, int], tuple[int, int]], default=True
|
|
269
|
+
Zoom settings for the inset axis.
|
|
270
|
+
- If True, uses the built-in zoom indication.
|
|
271
|
+
- If a tuple, manually connects the axes with zoom connectors.
|
|
272
|
+
zoom_color : ColorType, default='black'
|
|
273
|
+
Color for the zoom connectors and patches.
|
|
274
|
+
zoom_alpha : int | float, default=0.3
|
|
275
|
+
Transparency for the zoom connectors and patches.
|
|
276
|
+
zorder : int | float, default=5
|
|
277
|
+
The z-order of the inset axis.
|
|
278
|
+
**kwargs : Any
|
|
279
|
+
Additional keyword arguments for label configuration or other customizations.
|
|
280
|
+
|
|
281
|
+
Methods
|
|
282
|
+
--------------------
|
|
283
|
+
axes_inset() -> Axes:
|
|
284
|
+
Creates and configures the inset axis, applying zoom, labels, and minor ticks.
|
|
285
|
+
|
|
286
|
+
Examples
|
|
287
|
+
--------------------
|
|
288
|
+
>>> import matplotlib.pyplot as plt
|
|
289
|
+
>>> fig, ax = plt.subplots()
|
|
290
|
+
>>> bounds = [0.5, 0.5, 0.4, 0.4]
|
|
291
|
+
>>> axins = AxesInset(ax, bounds, lab_lims=["X", "Y", 0, 1, 0, 1]).axes_inset()
|
|
292
|
+
>>> plt.show()
|
|
293
|
+
"""
|
|
294
|
+
|
|
295
|
+
def __init__(
|
|
296
|
+
self,
|
|
297
|
+
ax: Axes,
|
|
298
|
+
bounds: tuple[float, float, float, float],
|
|
299
|
+
transform: Transform | None = None,
|
|
300
|
+
projection: str | None = None,
|
|
301
|
+
polar: bool = False,
|
|
302
|
+
lab_lims: list[Any] | None = None,
|
|
303
|
+
minor_ticks: bool = True,
|
|
304
|
+
zoom: bool | tuple[tuple[int, int], tuple[int, int]] = True,
|
|
305
|
+
zoom_color: ColorType = "black",
|
|
306
|
+
zoom_alpha: int | float = 0.3,
|
|
307
|
+
zorder: int | float = 5,
|
|
308
|
+
**kwargs: Any,
|
|
309
|
+
) -> None:
|
|
310
|
+
self.ax: Axes = ax
|
|
311
|
+
self.bounds: tuple[float, float, float, float] = bounds
|
|
312
|
+
self.transform: Transform | None = transform
|
|
313
|
+
self.projection: str | None = projection
|
|
314
|
+
self.polar: bool = polar
|
|
315
|
+
|
|
316
|
+
self.lab_lims: list[Any] | None = lab_lims
|
|
317
|
+
self.minor_ticks: bool = minor_ticks
|
|
318
|
+
self.zoom: bool | tuple[tuple[int, int], tuple[int, int]] = zoom
|
|
319
|
+
self.zoom_color: ColorType = zoom_color
|
|
320
|
+
self.zoom_alpha: int | float = zoom_alpha
|
|
321
|
+
self.zorder: int | float = zorder
|
|
322
|
+
self.kwargs: Any = kwargs
|
|
323
|
+
|
|
324
|
+
def axes_inset(self) -> Axes:
|
|
325
|
+
"""
|
|
326
|
+
Create and configure the inset axis.
|
|
327
|
+
|
|
328
|
+
This method creates an inset axis using the specified bounds and properties,
|
|
329
|
+
applies zoom connectors if specified, adds axis labels and limits, and enables
|
|
330
|
+
minor ticks.
|
|
331
|
+
|
|
332
|
+
Returns
|
|
333
|
+
--------------------
|
|
334
|
+
axins : Axes
|
|
335
|
+
The created inset axis.
|
|
336
|
+
|
|
337
|
+
Notes
|
|
338
|
+
--------------------
|
|
339
|
+
- If `lab_lims` is provided, the inset axis will be labeled and have custom limits.
|
|
340
|
+
- If `zoom` is specified, zoom connectors will be added between the main and inset axes.
|
|
341
|
+
|
|
342
|
+
Examples
|
|
343
|
+
--------------------
|
|
344
|
+
>>> axins = AxesInset(ax, bounds).axes_inset()
|
|
345
|
+
>>> axins.plot([0, 1], [0, 1])
|
|
346
|
+
"""
|
|
347
|
+
axins = self.ax.inset_axes(
|
|
348
|
+
bounds=self.bounds,
|
|
349
|
+
transform=self.transform,
|
|
350
|
+
projection=self.projection,
|
|
351
|
+
polar=self.polar,
|
|
352
|
+
zorder=self.zorder,
|
|
353
|
+
)
|
|
354
|
+
self._axes_inset_base = InsetAxesBase(
|
|
355
|
+
ax=self.ax,
|
|
356
|
+
axins=axins,
|
|
357
|
+
minor_ticks=self.minor_ticks,
|
|
358
|
+
zoom=self.zoom,
|
|
359
|
+
zoom_color=self.zoom_color,
|
|
360
|
+
zoom_alpha=self.zoom_alpha,
|
|
361
|
+
lab_lims=self.lab_lims,
|
|
362
|
+
**self.kwargs,
|
|
363
|
+
)
|
|
364
|
+
|
|
365
|
+
if self.lab_lims:
|
|
366
|
+
self._axes_inset_base.label()
|
|
367
|
+
if self.zoom:
|
|
368
|
+
self._axes_inset_base.inset_zoom()
|
|
369
|
+
self._axes_inset_base.set_minor_ticks()
|
|
370
|
+
return axins
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
@bind_passed_params()
|
|
374
|
+
def axes_inset(
|
|
375
|
+
ax: Axes,
|
|
376
|
+
bounds: tuple[float, float, float, float],
|
|
377
|
+
transform: Transform | None = None,
|
|
378
|
+
projection: str | None = None,
|
|
379
|
+
polar: bool = False,
|
|
380
|
+
lab_lims: list[Any] | None = None,
|
|
381
|
+
minor_ticks: bool = True,
|
|
382
|
+
zoom: bool | tuple[tuple[int, int], tuple[int, int]] = True,
|
|
383
|
+
zoom_color: ColorType = "black",
|
|
384
|
+
zoom_alpha: int | float = 0.3,
|
|
385
|
+
zorder: int | float = 5,
|
|
386
|
+
**kwargs: Any,
|
|
387
|
+
) -> Axes:
|
|
388
|
+
"""
|
|
389
|
+
A functional interface to create an inset axis in a Matplotlib figure.
|
|
390
|
+
|
|
391
|
+
This function wraps the `AxesInset` class, allowing inset axes to be created
|
|
392
|
+
with a simpler function-based interface.
|
|
393
|
+
|
|
394
|
+
Parameters
|
|
395
|
+
--------------------
|
|
396
|
+
ax : Axes
|
|
397
|
+
The main axis in the figure.
|
|
398
|
+
bounds : tuple[float, float, float, float]
|
|
399
|
+
Bounds for the inset axis in the format (x0, y0, width, height).
|
|
400
|
+
transform : Transform | None, optional
|
|
401
|
+
The transform to apply to the inset axis. Default is None.
|
|
402
|
+
projection : str | None, optional
|
|
403
|
+
The projection type for the inset axis. Default is None.
|
|
404
|
+
polar : bool, default=False
|
|
405
|
+
If True, the inset axis will use a polar projection.
|
|
406
|
+
lab_lims : list[Any] | None, optional
|
|
407
|
+
Axis labels and limits for the inset axis.
|
|
408
|
+
minor_ticks : bool, default=True
|
|
409
|
+
Whether to enable minor ticks on the inset axis.
|
|
410
|
+
zoom : bool or tuple[tuple[int, int], tuple[int, int]], default=True
|
|
411
|
+
Zoom settings for the inset axis.
|
|
412
|
+
zoom_color : ColorType, default='black'
|
|
413
|
+
Color for the zoom connectors and patches.
|
|
414
|
+
zoom_alpha : int | float, default=0.3
|
|
415
|
+
Transparency for the zoom connectors and patches.
|
|
416
|
+
zorder : int | float, default=5
|
|
417
|
+
The z-order of the inset axis.
|
|
418
|
+
**kwargs : Any
|
|
419
|
+
Additional keyword arguments for label configuration or other customizations.
|
|
420
|
+
|
|
421
|
+
Returns
|
|
422
|
+
--------------------
|
|
423
|
+
axins : Axes
|
|
424
|
+
The created inset axis.
|
|
425
|
+
|
|
426
|
+
Notes
|
|
427
|
+
--------------------
|
|
428
|
+
zoom provides manual inset zooming when a tuple is provided.
|
|
429
|
+
zoom = ((1, 2), (3, 4)) will connect the main axis to the inset axis as follows:
|
|
430
|
+
|
|
431
|
+
- 1 (main) - 2 (inset)
|
|
432
|
+
- 3 (main) - 3 (inset)
|
|
433
|
+
|
|
434
|
+
The indices represent the corners of the axes, with 1 being the bottom left corner
|
|
435
|
+
|
|
436
|
+
Examples
|
|
437
|
+
--------------------
|
|
438
|
+
>>> import matplotlib.pyplot as plt
|
|
439
|
+
>>> fig, ax = plt.subplots()
|
|
440
|
+
>>> axins = axes_inset(ax, [0.5, 0.5, 0.4, 0.4], lab_lims=["X", "Y", 0, 1, 0, 1])
|
|
441
|
+
>>> axins.plot([0, 1], [0, 1])
|
|
442
|
+
"""
|
|
443
|
+
|
|
444
|
+
passed_params: dict[str, Any] = ParamsGetter("passed_params").get_bound_params()
|
|
445
|
+
class_params = CreateClassParams(passed_params).get_class_params()
|
|
446
|
+
|
|
447
|
+
_axes_inset = AxesInset(
|
|
448
|
+
class_params["ax"],
|
|
449
|
+
class_params["bounds"],
|
|
450
|
+
class_params["transform"],
|
|
451
|
+
class_params["projection"],
|
|
452
|
+
class_params["polar"],
|
|
453
|
+
class_params["lab_lims"],
|
|
454
|
+
class_params["minor_ticks"],
|
|
455
|
+
class_params["zoom"],
|
|
456
|
+
class_params["zoom_color"],
|
|
457
|
+
class_params["zoom_alpha"],
|
|
458
|
+
class_params["zorder"],
|
|
459
|
+
**class_params["kwargs"],
|
|
460
|
+
)
|
|
461
|
+
axins = _axes_inset.axes_inset()
|
|
462
|
+
return axins
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
class AxesInsetPadding:
|
|
466
|
+
"""
|
|
467
|
+
A class to create and manage inset axes with padding in a Matplotlib figure.
|
|
468
|
+
|
|
469
|
+
This class facilitates the creation of inset axes with precise control over
|
|
470
|
+
size, location, and additional padding. It also supports zooming, labeling,
|
|
471
|
+
and minor tick customization.
|
|
472
|
+
|
|
473
|
+
Parameters
|
|
474
|
+
--------------------
|
|
475
|
+
ax : Axes
|
|
476
|
+
The parent axis where the inset axis will be placed.
|
|
477
|
+
width : str or float
|
|
478
|
+
The width of the inset axis. Can be a float (absolute size) or a string
|
|
479
|
+
(e.g., "30%" relative to the parent axis).
|
|
480
|
+
height : str or float
|
|
481
|
+
The height of the inset axis. Can be a float (absolute size) or a string
|
|
482
|
+
(e.g., "30%" relative to the parent axis).
|
|
483
|
+
loc : str, default="upper right"
|
|
484
|
+
The location of the inset axis relative to the parent axis. Accepted values are:
|
|
485
|
+
"upper right", "upper left", "lower left", "lower right", etc.
|
|
486
|
+
borderpad : float, default=0.5
|
|
487
|
+
Padding between the parent axis and the inset axis.
|
|
488
|
+
bbox_to_anchor : tuple[float, float] | BboxBase | None, optional
|
|
489
|
+
The bounding box to anchor the inset axis.
|
|
490
|
+
bbox_transform : Transform | None, optional
|
|
491
|
+
Transformation for the bounding box anchor.
|
|
492
|
+
axes_kwargs : dict[str, Any] | None, optional
|
|
493
|
+
Additional keyword arguments to pass to the inset axis creation.
|
|
494
|
+
lab_lims : list[Any] | None, optional
|
|
495
|
+
Axis labels and limits for the inset axis.
|
|
496
|
+
Expected format: [x_label, y_label, x_lim_min, x_lim_max, y_lim_min, y_lim_max].
|
|
497
|
+
minor_ticks : bool, default=True
|
|
498
|
+
Whether to enable minor ticks on the inset axis.
|
|
499
|
+
zoom : bool or tuple[tuple[int, int], tuple[int, int]], default=True
|
|
500
|
+
Zoom settings for the inset axis.
|
|
501
|
+
- If True, uses the built-in zoom indication.
|
|
502
|
+
- If a tuple, manually connects the axes with zoom connectors.
|
|
503
|
+
zoom_color : ColorType, default="black"
|
|
504
|
+
Color for the zoom connectors and patches.
|
|
505
|
+
zoom_alpha : int | float, default=0.3
|
|
506
|
+
Transparency for the zoom connectors and patches.
|
|
507
|
+
**kwargs : Any
|
|
508
|
+
Additional keyword arguments for label configuration or other customizations.
|
|
509
|
+
|
|
510
|
+
Methods
|
|
511
|
+
--------------------
|
|
512
|
+
axes_inset() -> Axes:
|
|
513
|
+
Creates and configures the inset axis with the specified parameters.
|
|
514
|
+
|
|
515
|
+
Examples
|
|
516
|
+
--------------------
|
|
517
|
+
>>> import matplotlib.pyplot as plt
|
|
518
|
+
>>> from mpl_toolkits.axes_grid1.inset_locator import inset_axes
|
|
519
|
+
>>> fig, ax = plt.subplots()
|
|
520
|
+
>>> axins = AxesInsetPadding(ax, width="30%", height="30%", loc="upper right").axes_inset()
|
|
521
|
+
>>> axins.plot([0, 1], [0, 1])
|
|
522
|
+
>>> plt.show()
|
|
523
|
+
"""
|
|
524
|
+
|
|
525
|
+
def __init__(
|
|
526
|
+
self,
|
|
527
|
+
ax: Axes,
|
|
528
|
+
width: str | float,
|
|
529
|
+
height: str | float,
|
|
530
|
+
loc: str = "upper right",
|
|
531
|
+
borderpad: float = 0.5,
|
|
532
|
+
bbox_to_anchor: tuple[float, float] | BboxBase | None = None,
|
|
533
|
+
bbox_transform: Transform | None = None,
|
|
534
|
+
axes_kwargs: dict[str, Any] | None = None,
|
|
535
|
+
lab_lims: list[Any] | None = None,
|
|
536
|
+
minor_ticks: bool = True,
|
|
537
|
+
zoom: bool | tuple[tuple[int, int], tuple[int, int]] = True,
|
|
538
|
+
zoom_color: ColorType = "black",
|
|
539
|
+
zoom_alpha: int | float = 0.3,
|
|
540
|
+
**kwargs: Any,
|
|
541
|
+
) -> None:
|
|
542
|
+
self.ax: Axes = ax
|
|
543
|
+
self.width: str | float = width
|
|
544
|
+
self.height: str | float = height
|
|
545
|
+
self.loc: str = loc
|
|
546
|
+
self.borderpad: float = borderpad
|
|
547
|
+
self.bbox_to_anchor: tuple[float, float] | BboxBase | None = bbox_to_anchor
|
|
548
|
+
self.bbox_transform: Transform | None = bbox_transform
|
|
549
|
+
self.axes_kwargs: dict[str, Any] | None = axes_kwargs
|
|
550
|
+
|
|
551
|
+
self.lab_lims: list[Any] | None = lab_lims
|
|
552
|
+
self.minor_ticks: bool = minor_ticks
|
|
553
|
+
self.zoom: bool | tuple[tuple[int, int], tuple[int, int]] = zoom
|
|
554
|
+
self.zoom_color: ColorType = zoom_color
|
|
555
|
+
self.zoom_alpha: int | float = zoom_alpha
|
|
556
|
+
self.kwargs: Any = kwargs
|
|
557
|
+
|
|
558
|
+
def axes_inset(self) -> Axes:
|
|
559
|
+
"""
|
|
560
|
+
Create and configure an inset axis with padding.
|
|
561
|
+
|
|
562
|
+
This method uses `inset_axes` to create an inset axis with the specified
|
|
563
|
+
width, height, and padding. It applies zoom connectors, labels, and minor
|
|
564
|
+
ticks if specified.
|
|
565
|
+
|
|
566
|
+
Returns
|
|
567
|
+
--------------------
|
|
568
|
+
axins : Axes
|
|
569
|
+
The created inset axis.
|
|
570
|
+
|
|
571
|
+
Notes
|
|
572
|
+
--------------------
|
|
573
|
+
- If `lab_lims` is provided, the inset axis will be labeled and have custom limits.
|
|
574
|
+
- If `zoom` is specified, zoom connectors will be added between the main and inset axes.
|
|
575
|
+
|
|
576
|
+
Examples
|
|
577
|
+
--------------------
|
|
578
|
+
>>> axins = AxesInsetPadding(ax, "30%", "30%", loc="upper right").axes_inset()
|
|
579
|
+
>>> axins.plot([0, 1], [0, 1])
|
|
580
|
+
"""
|
|
581
|
+
axins = inset_axes(
|
|
582
|
+
parent_axes=self.ax,
|
|
583
|
+
width=self.width,
|
|
584
|
+
height=self.height,
|
|
585
|
+
loc=self.loc,
|
|
586
|
+
borderpad=self.borderpad,
|
|
587
|
+
bbox_to_anchor=self.bbox_to_anchor,
|
|
588
|
+
bbox_transform=self.bbox_transform,
|
|
589
|
+
axes_kwargs=self.axes_kwargs,
|
|
590
|
+
)
|
|
591
|
+
self._axes_inset_base = InsetAxesBase(
|
|
592
|
+
ax=self.ax,
|
|
593
|
+
axins=axins,
|
|
594
|
+
minor_ticks=self.minor_ticks,
|
|
595
|
+
zoom=self.zoom,
|
|
596
|
+
zoom_color=self.zoom_color,
|
|
597
|
+
zoom_alpha=self.zoom_alpha,
|
|
598
|
+
lab_lims=self.lab_lims,
|
|
599
|
+
**self.kwargs,
|
|
600
|
+
)
|
|
601
|
+
|
|
602
|
+
if self.lab_lims:
|
|
603
|
+
self._axes_inset_base.label()
|
|
604
|
+
if self.zoom:
|
|
605
|
+
self._axes_inset_base.inset_zoom()
|
|
606
|
+
self._axes_inset_base.set_minor_ticks()
|
|
607
|
+
return cast(Axes, axins)
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
@bind_passed_params()
|
|
611
|
+
def axes_inset_padding(
|
|
612
|
+
ax: Axes,
|
|
613
|
+
width: str | float,
|
|
614
|
+
height: str | float,
|
|
615
|
+
loc: str = "upper right",
|
|
616
|
+
borderpad: float = 0.5,
|
|
617
|
+
bbox_to_anchor: tuple[float, float] | BboxBase | None = None,
|
|
618
|
+
bbox_transform: Transform | None = None,
|
|
619
|
+
axes_kwargs: dict[str, Any] | None = None,
|
|
620
|
+
lab_lims: list[Any] | None = None,
|
|
621
|
+
minor_ticks: bool = True,
|
|
622
|
+
zoom: bool | tuple[tuple[int, int], tuple[int, int]] = True,
|
|
623
|
+
zoom_color: ColorType = "black",
|
|
624
|
+
zoom_alpha: int | float = 0.3,
|
|
625
|
+
**kwargs: Any,
|
|
626
|
+
) -> Axes:
|
|
627
|
+
"""
|
|
628
|
+
A functional interface to create an inset axis with padding in a Matplotlib figure.
|
|
629
|
+
|
|
630
|
+
This function wraps the `AxesInsetPadding` class, allowing inset axes to be created
|
|
631
|
+
with a simpler function-based interface.
|
|
632
|
+
|
|
633
|
+
Parameters
|
|
634
|
+
--------------------
|
|
635
|
+
ax : Axes
|
|
636
|
+
The parent axis where the inset axis will be placed.
|
|
637
|
+
width : str or float
|
|
638
|
+
The width of the inset axis.
|
|
639
|
+
height : str or float
|
|
640
|
+
The height of the inset axis.
|
|
641
|
+
loc : str, default="upper right"
|
|
642
|
+
The location of the inset axis relative to the parent axis.
|
|
643
|
+
borderpad : float, default=0.5
|
|
644
|
+
Padding between the parent axis and the inset axis.
|
|
645
|
+
bbox_to_anchor : tuple[float, float] | BboxBase | None, optional
|
|
646
|
+
Bounding box to anchor the inset axis.
|
|
647
|
+
bbox_transform : Transform | None, optional
|
|
648
|
+
Transformation for the bounding box anchor.
|
|
649
|
+
axes_kwargs : dict[str, Any] | None, optional
|
|
650
|
+
Additional keyword arguments for the inset axis creation.
|
|
651
|
+
lab_lims : list[Any] | None, optional
|
|
652
|
+
Axis labels and limits for the inset axis.
|
|
653
|
+
minor_ticks : bool, default=True
|
|
654
|
+
Whether to enable minor ticks on the inset axis.
|
|
655
|
+
zoom : bool or tuple[tuple[int, int], tuple[int, int]], default=True
|
|
656
|
+
Zoom settings for the inset axis.
|
|
657
|
+
zoom_color : ColorType, default="black"
|
|
658
|
+
Color for the zoom connectors and patches.
|
|
659
|
+
zoom_alpha : int | float, default=0.3
|
|
660
|
+
Transparency for the zoom connectors and patches.
|
|
661
|
+
**kwargs : Any
|
|
662
|
+
Additional keyword arguments for label configuration or other customizations.
|
|
663
|
+
|
|
664
|
+
Returns
|
|
665
|
+
--------------------
|
|
666
|
+
axins : Axes
|
|
667
|
+
The created inset axis.
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
Notes
|
|
671
|
+
--------------------
|
|
672
|
+
zoom provides manual inset zooming when a tuple is provided.
|
|
673
|
+
zoom = ((1, 2), (3, 4)) will connect the main axis to the inset axis as follows:
|
|
674
|
+
|
|
675
|
+
- 1 (main) - 2 (inset)
|
|
676
|
+
- 3 (main) - 3 (inset)
|
|
677
|
+
|
|
678
|
+
The indices represent the corners of the axes, with 1 being the bottom left corner
|
|
679
|
+
|
|
680
|
+
Examples
|
|
681
|
+
--------------------
|
|
682
|
+
>>> import matplotlib.pyplot as plt
|
|
683
|
+
>>> fig, ax = plt.subplots()
|
|
684
|
+
>>> axins = axes_inset_padding(ax, "30%", "30%", loc="upper right", zoom=False)
|
|
685
|
+
>>> axins.plot([0, 1], [0, 1])
|
|
686
|
+
"""
|
|
687
|
+
|
|
688
|
+
passed_params: dict[str, Any] = ParamsGetter("passed_params").get_bound_params()
|
|
689
|
+
class_params = CreateClassParams(passed_params).get_class_params()
|
|
690
|
+
|
|
691
|
+
_axes_inset_padding = AxesInsetPadding(
|
|
692
|
+
class_params["ax"],
|
|
693
|
+
class_params["width"],
|
|
694
|
+
class_params["height"],
|
|
695
|
+
class_params["loc"],
|
|
696
|
+
class_params["borderpad"],
|
|
697
|
+
class_params["bbox_to_anchor"],
|
|
698
|
+
class_params["bbox_transform"],
|
|
699
|
+
class_params["axes_kwargs"],
|
|
700
|
+
class_params["lab_lims"],
|
|
701
|
+
class_params["minor_ticks"],
|
|
702
|
+
class_params["zoom"],
|
|
703
|
+
class_params["zoom_color"],
|
|
704
|
+
class_params["zoom_alpha"],
|
|
705
|
+
**class_params["kwargs"],
|
|
706
|
+
)
|
|
707
|
+
axins = _axes_inset_padding.axes_inset()
|
|
708
|
+
return axins
|
|
@@ -452,31 +452,39 @@ class Label:
|
|
|
452
452
|
lab_lims : list[Any]
|
|
453
453
|
A list specifying labels and limits for each axis in the figure. Each entry
|
|
454
454
|
should be a tuple of the form `(x_label, y_label, x_limits, y_limits)`.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
455
|
+
xpad_label : int or float, default=5
|
|
456
|
+
Padding for the x-axis label.
|
|
457
|
+
ypad_label : int or float, default=5
|
|
458
|
+
Padding for the y-axis label.
|
|
459
459
|
minor_ticks_axes : bool, default=True
|
|
460
460
|
Whether to add minor ticks to all axes.
|
|
461
461
|
tight_layout : bool, default=True
|
|
462
462
|
Whether to apply `tight_layout` to the figure.
|
|
463
|
+
xpad_layout : int, default=2
|
|
464
|
+
Horizontal padding for tight layout.
|
|
465
|
+
ypad_layout : int, default=2
|
|
466
|
+
Vertical padding for tight layout.
|
|
463
467
|
*args : Any
|
|
464
|
-
Additional arguments for `
|
|
468
|
+
Additional arguments for `ax.set_xlabel` and `ax.set_ylabel.
|
|
465
469
|
**kwargs : Any
|
|
466
|
-
Additional keyword arguments for `
|
|
470
|
+
Additional keyword arguments for `ax.set_xlabel` and `ax.set_ylabel`.
|
|
467
471
|
|
|
468
472
|
Attributes
|
|
469
473
|
--------------------
|
|
470
474
|
lab_lims : list[Any]
|
|
471
475
|
The labels and limits configuration for the axes.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
+
xpad_label : int or float
|
|
477
|
+
Padding for the x-axis label.
|
|
478
|
+
ypad_label : int or float
|
|
479
|
+
Padding for the y-axis label.
|
|
476
480
|
minor_ticks_axes : bool
|
|
477
481
|
Whether minor ticks are enabled for axes.
|
|
478
482
|
tight_layout : bool
|
|
479
483
|
Whether `tight_layout` is applied.
|
|
484
|
+
xpad_layout : int
|
|
485
|
+
Horizontal padding for tight layout.
|
|
486
|
+
ypad_layout : int
|
|
487
|
+
Vertical padding for tight layout.
|
|
480
488
|
_axes : list[Axes]
|
|
481
489
|
List of axes in the current figure.
|
|
482
490
|
|
|
@@ -507,20 +515,22 @@ class Label:
|
|
|
507
515
|
def __init__(
|
|
508
516
|
self,
|
|
509
517
|
lab_lims: list[Any],
|
|
510
|
-
|
|
511
|
-
|
|
518
|
+
xpad_label: int | float = 2,
|
|
519
|
+
ypad_label: int | float = 2,
|
|
512
520
|
minor_ticks_axes: bool = True,
|
|
513
521
|
tight_layout: bool = True,
|
|
514
|
-
|
|
522
|
+
xpad_layout: int | float = 2,
|
|
523
|
+
ypad_layout: int | float = 2,
|
|
515
524
|
**kwargs: Any,
|
|
516
525
|
) -> None:
|
|
517
526
|
|
|
518
527
|
self.lab_lims: list[Any] = lab_lims
|
|
519
|
-
self.
|
|
520
|
-
self.
|
|
528
|
+
self.xpad_label: int | float = xpad_label
|
|
529
|
+
self.ypad_label: int | float = ypad_label
|
|
521
530
|
self.minor_ticks_axes: bool = minor_ticks_axes
|
|
522
531
|
self.tight_layout: bool = tight_layout
|
|
523
|
-
self.
|
|
532
|
+
self.xpad_layout: int | float = xpad_layout
|
|
533
|
+
self.ypad_layout: int | float = ypad_layout
|
|
524
534
|
self.kwargs: Any = kwargs
|
|
525
535
|
|
|
526
536
|
self._axes: list[Axes] = plt.gcf().axes
|
|
@@ -621,7 +631,15 @@ class Label:
|
|
|
621
631
|
if self.minor_ticks_axes:
|
|
622
632
|
MinorTicksAxes().set_minor_ticks_axes()
|
|
623
633
|
|
|
624
|
-
def configure_axis_labels(
|
|
634
|
+
def configure_axis_labels(
|
|
635
|
+
self,
|
|
636
|
+
ax: Axes,
|
|
637
|
+
x_lab: str | None,
|
|
638
|
+
y_lab: str | None,
|
|
639
|
+
xpad_label: int | float = 10,
|
|
640
|
+
ypad_label: int | float = 10,
|
|
641
|
+
**kwargs: Any,
|
|
642
|
+
) -> None:
|
|
625
643
|
"""
|
|
626
644
|
Configures the labels for a given axis.
|
|
627
645
|
|
|
@@ -633,20 +651,31 @@ class Label:
|
|
|
633
651
|
The label for the x-axis. If `None`, the x-axis label is removed.
|
|
634
652
|
y_lab : str, optional
|
|
635
653
|
The label for the y-axis. If `None`, the y-axis label is removed.
|
|
654
|
+
xpad_label : int or float, default=5
|
|
655
|
+
Padding for the x-axis label.
|
|
656
|
+
ypad_label : int or float, default=5
|
|
657
|
+
Padding for the y-axis label.
|
|
658
|
+
**kwargs : Any
|
|
659
|
+
Additional keyword arguments for the labels.
|
|
636
660
|
|
|
637
661
|
Returns
|
|
638
662
|
--------------------
|
|
639
663
|
None
|
|
640
664
|
"""
|
|
641
|
-
if x_lab:
|
|
642
|
-
ax.set_xlabel(x_lab)
|
|
643
|
-
else:
|
|
644
|
-
self.remove_xlabels(ax)
|
|
645
665
|
|
|
646
|
-
if
|
|
647
|
-
ax.
|
|
666
|
+
if isinstance(x_lab, str):
|
|
667
|
+
ax.set_xlabel(xlabel=x_lab, labelpad=xpad_label, **kwargs)
|
|
668
|
+
elif x_lab is None:
|
|
669
|
+
self.remove_xlabels(ax)
|
|
648
670
|
else:
|
|
671
|
+
raise ValueError("Invalid x-axis label. Must be a string or None.")
|
|
672
|
+
|
|
673
|
+
if isinstance(y_lab, str):
|
|
674
|
+
ax.set_ylabel(ylabel=y_lab, labelpad=ypad_label, **kwargs)
|
|
675
|
+
elif y_lab is None:
|
|
649
676
|
self.remove_ylabels(ax)
|
|
677
|
+
else:
|
|
678
|
+
raise ValueError("Invalid y-axis label. Must be a string or None.")
|
|
650
679
|
|
|
651
680
|
def configure_axis_limits(
|
|
652
681
|
self,
|
|
@@ -672,6 +701,7 @@ class Label:
|
|
|
672
701
|
--------------------
|
|
673
702
|
None
|
|
674
703
|
"""
|
|
704
|
+
|
|
675
705
|
if lims:
|
|
676
706
|
x_lims, y_lims = lims
|
|
677
707
|
|
|
@@ -710,18 +740,40 @@ class Label:
|
|
|
710
740
|
)
|
|
711
741
|
|
|
712
742
|
def set_labels(self):
|
|
743
|
+
"""
|
|
744
|
+
Applies labels, limits, and scales to all axes based on the configuration.
|
|
745
|
+
|
|
746
|
+
Returns
|
|
747
|
+
--------------------
|
|
748
|
+
None
|
|
749
|
+
|
|
750
|
+
"""
|
|
713
751
|
final_axes_ranges = self._get_final_axes_ranges()
|
|
714
752
|
|
|
715
753
|
for i, (x_lab, y_lab, *lims) in enumerate(self.lab_lims):
|
|
716
754
|
ax = self._axes[i]
|
|
717
755
|
|
|
718
756
|
# Configure axis labels
|
|
719
|
-
self.configure_axis_labels(
|
|
757
|
+
self.configure_axis_labels(
|
|
758
|
+
ax, x_lab, y_lab, self.xpad_label, self.ypad_label, **self.kwargs
|
|
759
|
+
)
|
|
720
760
|
|
|
721
761
|
# Configure axis limits and scales
|
|
722
762
|
self.configure_axis_limits(ax, lims, final_axes_ranges)
|
|
723
763
|
|
|
724
764
|
def _calculate_padding_range(self, range: NDArray[Any]) -> NDArray[Any]:
|
|
765
|
+
"""
|
|
766
|
+
Calculates the padding range for a given axis.
|
|
767
|
+
|
|
768
|
+
Parameters
|
|
769
|
+
--------------------
|
|
770
|
+
range : numpy.ndarray
|
|
771
|
+
The range of values for the axis.
|
|
772
|
+
|
|
773
|
+
Returns
|
|
774
|
+
--------------------
|
|
775
|
+
numpy.ndarray
|
|
776
|
+
"""
|
|
725
777
|
|
|
726
778
|
PADDING_FACTOR: float = 0.05
|
|
727
779
|
span: float = range[1] - range[0]
|
|
@@ -732,11 +784,32 @@ class Label:
|
|
|
732
784
|
def _get_wider_range(
|
|
733
785
|
self, range1: NDArray[Any], range2: NDArray[Any]
|
|
734
786
|
) -> NDArray[Any]:
|
|
787
|
+
"""
|
|
788
|
+
Calculates the wider range between two ranges.
|
|
789
|
+
|
|
790
|
+
Parameters
|
|
791
|
+
--------------------
|
|
792
|
+
range1 : numpy.ndarray
|
|
793
|
+
The first range of values.
|
|
794
|
+
range2 : numpy.ndarray
|
|
795
|
+
The second range of values.
|
|
796
|
+
|
|
797
|
+
Returns
|
|
798
|
+
--------------------
|
|
799
|
+
numpy.ndarray
|
|
800
|
+
"""
|
|
735
801
|
|
|
736
802
|
new_range = np.array([min(range1[0], range2[0]), max(range1[1], range2[1])])
|
|
737
803
|
return new_range
|
|
738
804
|
|
|
739
805
|
def _get_axes_ranges_current(self) -> list[list[NDArray[Any]]]:
|
|
806
|
+
"""
|
|
807
|
+
Retrieves the current ranges for all axes.
|
|
808
|
+
|
|
809
|
+
Returns
|
|
810
|
+
--------------------
|
|
811
|
+
list[list[numpy.ndarray]]
|
|
812
|
+
"""
|
|
740
813
|
|
|
741
814
|
axes_ranges_current = []
|
|
742
815
|
for ax in self._axes:
|
|
@@ -746,6 +819,13 @@ class Label:
|
|
|
746
819
|
return axes_ranges_current
|
|
747
820
|
|
|
748
821
|
def _get_final_axes_ranges(self) -> dict[Axes, list[NDArray[Any]]]:
|
|
822
|
+
"""
|
|
823
|
+
Retrieves the final axes ranges for all axes.
|
|
824
|
+
|
|
825
|
+
Returns
|
|
826
|
+
--------------------
|
|
827
|
+
dict[matplotlib.axes.Axes, list[numpy.ndarray]]
|
|
828
|
+
"""
|
|
749
829
|
_axes_range_singleton = AxesRangeSingleton()
|
|
750
830
|
|
|
751
831
|
axes_ranges_current = self._get_axes_ranges_current()
|
|
@@ -780,21 +860,28 @@ class Label:
|
|
|
780
860
|
|
|
781
861
|
#! Xpad and Ypad will change the size of the axis
|
|
782
862
|
def apply_tight_layout(self) -> None:
|
|
863
|
+
"""
|
|
864
|
+
Applies `tight_layout` to the figure.
|
|
783
865
|
|
|
866
|
+
Returns
|
|
867
|
+
--------------------
|
|
868
|
+
None
|
|
869
|
+
"""
|
|
784
870
|
if self.tight_layout:
|
|
785
871
|
# Ignore this warning when using inset_axes:
|
|
786
872
|
# UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect
|
|
787
873
|
with warnings.catch_warnings():
|
|
788
874
|
warnings.simplefilter("ignore")
|
|
789
|
-
|
|
790
|
-
plt.tight_layout(
|
|
791
|
-
w_pad=self.x_pad, h_pad=self.y_pad, *self.args, **self.kwargs
|
|
792
|
-
)
|
|
793
|
-
except Exception:
|
|
794
|
-
plt.tight_layout(w_pad=self.x_pad, h_pad=self.y_pad)
|
|
875
|
+
plt.tight_layout(w_pad=self.xpad_layout, h_pad=self.ypad_layout)
|
|
795
876
|
|
|
796
877
|
def label(self) -> None:
|
|
878
|
+
"""
|
|
879
|
+
Adds labels, limits, and layouts to the figure's axes.
|
|
797
880
|
|
|
881
|
+
Returns
|
|
882
|
+
--------------------
|
|
883
|
+
None
|
|
884
|
+
"""
|
|
798
885
|
self.add_minor_ticks_axes()
|
|
799
886
|
self.set_labels()
|
|
800
887
|
self.apply_tight_layout()
|
|
@@ -804,10 +891,12 @@ class Label:
|
|
|
804
891
|
@track_order
|
|
805
892
|
def label(
|
|
806
893
|
lab_lims: list[Any],
|
|
807
|
-
|
|
808
|
-
|
|
894
|
+
xpad_label: int | float = 5,
|
|
895
|
+
ypad_label: int | float = 5,
|
|
809
896
|
minor_ticks_axes: bool = True,
|
|
810
897
|
tight_layout: bool = True,
|
|
898
|
+
xpad_layout: int = 2,
|
|
899
|
+
ypad_layout: int = 2,
|
|
811
900
|
*args: Any,
|
|
812
901
|
**kwargs: Any,
|
|
813
902
|
) -> None:
|
|
@@ -821,18 +910,22 @@ def label(
|
|
|
821
910
|
lab_lims : list[Any]
|
|
822
911
|
A list specifying labels and limits for each axis in the figure. Each entry
|
|
823
912
|
should be a tuple of the form `(x_label, y_label, x_limits, y_limits)`.
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
913
|
+
xpad_label : int or float, default=5
|
|
914
|
+
Padding for the x-axis label.
|
|
915
|
+
ypad_label : int or float, default=5
|
|
916
|
+
Padding for the y-axis label.
|
|
828
917
|
minor_ticks_axes : bool, default=True
|
|
829
918
|
Whether to add minor ticks to all axes.
|
|
830
919
|
tight_layout : bool, default=True
|
|
831
920
|
Whether to apply `tight_layout` to the figure.
|
|
921
|
+
xpad_layout : int, default=2
|
|
922
|
+
Horizontal padding for tight layout.
|
|
923
|
+
ypad_layout : int, default=2
|
|
924
|
+
Vertical padding for tight layout.
|
|
832
925
|
*args : Any
|
|
833
|
-
Additional arguments for `
|
|
926
|
+
Additional arguments for `ax.set_xlabel` and `ax.set_ylabel.
|
|
834
927
|
**kwargs : Any
|
|
835
|
-
Additional keyword arguments for `
|
|
928
|
+
Additional keyword arguments for `ax.set_xlabel` and `ax.set_ylabel`.
|
|
836
929
|
|
|
837
930
|
Notes
|
|
838
931
|
--------------------
|
|
@@ -853,8 +946,8 @@ def label(
|
|
|
853
946
|
>>> import gsplot as gs
|
|
854
947
|
>>> gs.label(
|
|
855
948
|
>>> lab_lims=[("X Label", "Y Label", [1, 10, "log"], [1, 20, 2])],
|
|
856
|
-
>>>
|
|
857
|
-
>>>
|
|
949
|
+
>>> xpad_layout=5,
|
|
950
|
+
>>> ypad_layout=5,
|
|
858
951
|
>>> )
|
|
859
952
|
"""
|
|
860
953
|
|
|
@@ -863,11 +956,12 @@ def label(
|
|
|
863
956
|
|
|
864
957
|
_label = Label(
|
|
865
958
|
class_params["lab_lims"],
|
|
866
|
-
class_params["
|
|
867
|
-
class_params["
|
|
959
|
+
class_params["xpad_label"],
|
|
960
|
+
class_params["ypad_label"],
|
|
868
961
|
class_params["minor_ticks_axes"],
|
|
869
962
|
class_params["tight_layout"],
|
|
870
|
-
|
|
963
|
+
class_params["xpad_layout"],
|
|
964
|
+
class_params["ypad_layout"],
|
|
871
965
|
**class_params["kwargs"],
|
|
872
966
|
)
|
|
873
967
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from typing import Any
|
|
2
3
|
|
|
3
4
|
import matplotlib.pyplot as plt
|
|
@@ -197,8 +198,10 @@ class LegendAxes:
|
|
|
197
198
|
"""
|
|
198
199
|
_lg_list = []
|
|
199
200
|
for ax in plt.gcf().axes:
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
with warnings.catch_warnings():
|
|
202
|
+
warnings.simplefilter("ignore")
|
|
203
|
+
_lg = ax.legend(*self.args, **self.kwargs)
|
|
204
|
+
_lg_list.append(_lg)
|
|
202
205
|
return _lg_list
|
|
203
206
|
|
|
204
207
|
|
gsplot-0.1.0/gsplot/version.py
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|