matplotlibx 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- matplotlibx-0.1.0.dist-info/METADATA +277 -0
- matplotlibx-0.1.0.dist-info/RECORD +10 -0
- matplotlibx-0.1.0.dist-info/WHEEL +5 -0
- matplotlibx-0.1.0.dist-info/licenses/LICENSE +21 -0
- matplotlibx-0.1.0.dist-info/top_level.txt +1 -0
- pltx/__init__.py +3 -0
- pltx/colors.py +335 -0
- pltx/pyplot.py +582 -0
- pltx/rcparams.py +322 -0
- pltx/style.py +778 -0
pltx/pyplot.py
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
"""Enhanced pyplot interface for pltx.
|
|
2
|
+
|
|
3
|
+
This module provides a drop-in replacement for matplotlib.pyplot with
|
|
4
|
+
automatic styling and enhanced convenience functions.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Optional, Tuple, List, Union
|
|
8
|
+
import numpy as np
|
|
9
|
+
from matplotlib.pyplot import * # noqa: F403
|
|
10
|
+
from matplotlib.pyplot import gca # noqa: F401
|
|
11
|
+
|
|
12
|
+
from .style import PlotStyle
|
|
13
|
+
from .rcparams import StylePreset, apply_style_preset
|
|
14
|
+
|
|
15
|
+
# Initialize default style
|
|
16
|
+
_default_style: Optional[PlotStyle] = None
|
|
17
|
+
_style_initialized = False
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def initialize_style(
|
|
21
|
+
palette_name: str = "plasma_r",
|
|
22
|
+
palette_size: int = 10,
|
|
23
|
+
font_size_medium: int = 12,
|
|
24
|
+
font_size_large: int = 13,
|
|
25
|
+
use_tex: bool = False,
|
|
26
|
+
vary_linewidth: bool = False,
|
|
27
|
+
base_linewidth: float = 2.0,
|
|
28
|
+
linewidth_progression_factor: float = 1.3,
|
|
29
|
+
) -> PlotStyle:
|
|
30
|
+
"""Initialize the default plotting style for pltx.
|
|
31
|
+
|
|
32
|
+
This function should be called once at the beginning of your script
|
|
33
|
+
to set up the global plotting style.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
palette_name : str
|
|
38
|
+
Name of the seaborn color palette
|
|
39
|
+
palette_size : int
|
|
40
|
+
Number of colors in the palette
|
|
41
|
+
font_size_medium : int
|
|
42
|
+
Standard font size for labels, ticks
|
|
43
|
+
font_size_large : int
|
|
44
|
+
Font size for titles
|
|
45
|
+
use_tex : bool
|
|
46
|
+
Whether to use LaTeX rendering
|
|
47
|
+
vary_linewidth : bool
|
|
48
|
+
If True, automatically vary line widths for colorblind accessibility.
|
|
49
|
+
Each line gets progressively thicker.
|
|
50
|
+
base_linewidth : float
|
|
51
|
+
Base line width when vary_linewidth is True
|
|
52
|
+
linewidth_progression_factor : float
|
|
53
|
+
Factor for progressive width increase (e.g., 1.2 = 20% increase per line)
|
|
54
|
+
|
|
55
|
+
Returns
|
|
56
|
+
-------
|
|
57
|
+
PlotStyle
|
|
58
|
+
The initialized plot style object
|
|
59
|
+
"""
|
|
60
|
+
global _default_style, _style_initialized
|
|
61
|
+
|
|
62
|
+
_default_style = PlotStyle(
|
|
63
|
+
palette_name=palette_name,
|
|
64
|
+
palette_size=palette_size,
|
|
65
|
+
font_size_medium=font_size_medium,
|
|
66
|
+
font_size_large=font_size_large,
|
|
67
|
+
use_tex=use_tex,
|
|
68
|
+
vary_linewidth=vary_linewidth,
|
|
69
|
+
base_linewidth=base_linewidth,
|
|
70
|
+
linewidth_progression_factor=linewidth_progression_factor,
|
|
71
|
+
auto_apply=True,
|
|
72
|
+
)
|
|
73
|
+
_style_initialized = True
|
|
74
|
+
|
|
75
|
+
return _default_style
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def get_style() -> PlotStyle:
|
|
79
|
+
"""Get the current default plotting style.
|
|
80
|
+
|
|
81
|
+
If no style has been initialized, creates one with default settings.
|
|
82
|
+
|
|
83
|
+
Returns
|
|
84
|
+
-------
|
|
85
|
+
PlotStyle
|
|
86
|
+
The current plot style object
|
|
87
|
+
"""
|
|
88
|
+
global _default_style, _style_initialized
|
|
89
|
+
|
|
90
|
+
if not _style_initialized or _default_style is None:
|
|
91
|
+
_default_style = initialize_style()
|
|
92
|
+
|
|
93
|
+
return _default_style
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def style_context(preset: StylePreset, **kwargs):
|
|
97
|
+
"""Context manager for temporary style application.
|
|
98
|
+
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
preset : str
|
|
102
|
+
Style preset name ('nature', 'presentation', 'poster', etc.)
|
|
103
|
+
**kwargs
|
|
104
|
+
Optional rcParams overrides
|
|
105
|
+
"""
|
|
106
|
+
return get_style().style_context(preset, **kwargs)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def reset_color_cycle() -> None:
|
|
110
|
+
"""Reset the automatic color cycling index to zero."""
|
|
111
|
+
get_style().reset_color_cycle()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def setup_axis(
|
|
115
|
+
ax=None,
|
|
116
|
+
xlim: Optional[Tuple[float, float]] = None,
|
|
117
|
+
ylim: Optional[Tuple[float, float]] = None,
|
|
118
|
+
xlabel: Optional[str] = None,
|
|
119
|
+
ylabel: Optional[str] = None,
|
|
120
|
+
title: Optional[str] = None,
|
|
121
|
+
xscale: str = "linear",
|
|
122
|
+
yscale: str = "linear",
|
|
123
|
+
xtick_spacing: Optional[float] = None,
|
|
124
|
+
ytick_spacing: Optional[float] = None,
|
|
125
|
+
grid: bool = False,
|
|
126
|
+
grid_alpha: float = 0.3,
|
|
127
|
+
):
|
|
128
|
+
"""Setup axis with consistent styling.
|
|
129
|
+
|
|
130
|
+
Parameters
|
|
131
|
+
----------
|
|
132
|
+
ax : Axes, optional
|
|
133
|
+
Axis to setup. If None, uses current axis.
|
|
134
|
+
xlim, ylim : tuple, optional
|
|
135
|
+
Axis limits
|
|
136
|
+
xlabel, ylabel, title : str, optional
|
|
137
|
+
Axis labels and title
|
|
138
|
+
xscale, yscale : str
|
|
139
|
+
Axis scales ('linear', 'log', etc.)
|
|
140
|
+
xtick_spacing, ytick_spacing : float, optional
|
|
141
|
+
Tick spacing
|
|
142
|
+
grid : bool
|
|
143
|
+
Whether to show grid
|
|
144
|
+
grid_alpha : float
|
|
145
|
+
Grid transparency
|
|
146
|
+
"""
|
|
147
|
+
if ax is None:
|
|
148
|
+
ax = gca()
|
|
149
|
+
|
|
150
|
+
style = get_style()
|
|
151
|
+
style.setup_axis(
|
|
152
|
+
ax=ax,
|
|
153
|
+
xlim=xlim,
|
|
154
|
+
ylim=ylim,
|
|
155
|
+
xlabel=xlabel,
|
|
156
|
+
ylabel=ylabel,
|
|
157
|
+
title=title,
|
|
158
|
+
xscale=xscale,
|
|
159
|
+
yscale=yscale,
|
|
160
|
+
xtick_spacing=xtick_spacing,
|
|
161
|
+
ytick_spacing=ytick_spacing,
|
|
162
|
+
grid=grid,
|
|
163
|
+
grid_alpha=grid_alpha,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def plot_styled(
|
|
168
|
+
x: np.ndarray,
|
|
169
|
+
y: np.ndarray,
|
|
170
|
+
label: Optional[str] = None,
|
|
171
|
+
color: Optional[Union[str, tuple]] = None,
|
|
172
|
+
color_idx: Optional[int] = None,
|
|
173
|
+
color_intensity: Optional[float] = None,
|
|
174
|
+
linestyle: str = "-",
|
|
175
|
+
linewidth: float = 2,
|
|
176
|
+
marker: Optional[str] = None,
|
|
177
|
+
markersize: Optional[float] = None,
|
|
178
|
+
alpha: Optional[float] = None,
|
|
179
|
+
outline: bool = False,
|
|
180
|
+
outline_color: str = "black",
|
|
181
|
+
outline_width: Optional[float] = None,
|
|
182
|
+
ax=None,
|
|
183
|
+
**kwargs,
|
|
184
|
+
):
|
|
185
|
+
"""Plot with automatic color cycling and styling.
|
|
186
|
+
|
|
187
|
+
This is an enhanced version of plt.plot that uses pltx color palettes
|
|
188
|
+
and styling by default.
|
|
189
|
+
|
|
190
|
+
Parameters
|
|
191
|
+
----------
|
|
192
|
+
x, y : array-like
|
|
193
|
+
Data to plot
|
|
194
|
+
label : str, optional
|
|
195
|
+
Label for legend
|
|
196
|
+
color : str or tuple, optional
|
|
197
|
+
Line color
|
|
198
|
+
color_idx : int, optional
|
|
199
|
+
Index into color palette
|
|
200
|
+
color_intensity : float, optional
|
|
201
|
+
Color intensity adjustment (0.0-1.0)
|
|
202
|
+
linestyle, linewidth, marker, markersize :
|
|
203
|
+
Line and marker style parameters
|
|
204
|
+
alpha : float, optional
|
|
205
|
+
Transparency
|
|
206
|
+
outline : bool
|
|
207
|
+
If True, adds a thin black outline for better visibility
|
|
208
|
+
outline_color : str
|
|
209
|
+
Color of the outline (default: 'black')
|
|
210
|
+
outline_width : float, optional
|
|
211
|
+
Width of the outline. If None, uses linewidth + 2
|
|
212
|
+
ax : Axes, optional
|
|
213
|
+
Axis to plot on. If None, uses current axis.
|
|
214
|
+
**kwargs
|
|
215
|
+
Additional arguments passed to plot
|
|
216
|
+
|
|
217
|
+
Returns
|
|
218
|
+
-------
|
|
219
|
+
Line2D
|
|
220
|
+
The plotted line object
|
|
221
|
+
"""
|
|
222
|
+
if ax is None:
|
|
223
|
+
ax = gca()
|
|
224
|
+
|
|
225
|
+
style = get_style()
|
|
226
|
+
return style.plot_curve(
|
|
227
|
+
ax=ax,
|
|
228
|
+
x=x,
|
|
229
|
+
y=y,
|
|
230
|
+
label=label,
|
|
231
|
+
color=color,
|
|
232
|
+
color_idx=color_idx,
|
|
233
|
+
color_intensity=color_intensity,
|
|
234
|
+
linestyle=linestyle,
|
|
235
|
+
linewidth=linewidth,
|
|
236
|
+
marker=marker,
|
|
237
|
+
markersize=markersize,
|
|
238
|
+
alpha=alpha,
|
|
239
|
+
outline=outline,
|
|
240
|
+
outline_color=outline_color,
|
|
241
|
+
outline_width=outline_width,
|
|
242
|
+
**kwargs,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def scatter_styled(
|
|
247
|
+
x: np.ndarray,
|
|
248
|
+
y: np.ndarray,
|
|
249
|
+
label: Optional[str] = None,
|
|
250
|
+
color: Optional[Union[str, tuple]] = None,
|
|
251
|
+
color_idx: Optional[int] = None,
|
|
252
|
+
size: float = 20,
|
|
253
|
+
marker: str = "o",
|
|
254
|
+
alpha: Optional[float] = None,
|
|
255
|
+
ax=None,
|
|
256
|
+
**kwargs,
|
|
257
|
+
):
|
|
258
|
+
"""Scatter plot with automatic color cycling and styling.
|
|
259
|
+
|
|
260
|
+
Parameters
|
|
261
|
+
----------
|
|
262
|
+
x, y : array-like
|
|
263
|
+
Data to plot
|
|
264
|
+
label : str, optional
|
|
265
|
+
Label for legend
|
|
266
|
+
color : str or tuple, optional
|
|
267
|
+
Point color
|
|
268
|
+
color_idx : int, optional
|
|
269
|
+
Index into color palette
|
|
270
|
+
size : float
|
|
271
|
+
Marker size
|
|
272
|
+
marker : str
|
|
273
|
+
Marker style
|
|
274
|
+
alpha : float, optional
|
|
275
|
+
Transparency
|
|
276
|
+
ax : Axes, optional
|
|
277
|
+
Axis to plot on. If None, uses current axis.
|
|
278
|
+
**kwargs
|
|
279
|
+
Additional arguments passed to scatter
|
|
280
|
+
"""
|
|
281
|
+
if ax is None:
|
|
282
|
+
ax = gca()
|
|
283
|
+
|
|
284
|
+
style = get_style()
|
|
285
|
+
return style.scatter_styled(
|
|
286
|
+
ax=ax,
|
|
287
|
+
x=x,
|
|
288
|
+
y=y,
|
|
289
|
+
label=label,
|
|
290
|
+
color=color,
|
|
291
|
+
color_idx=color_idx,
|
|
292
|
+
size=size,
|
|
293
|
+
marker=marker,
|
|
294
|
+
alpha=alpha,
|
|
295
|
+
**kwargs,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def errorbar_styled(
|
|
300
|
+
x: np.ndarray,
|
|
301
|
+
y: np.ndarray,
|
|
302
|
+
yerr: Optional[np.ndarray] = None,
|
|
303
|
+
xerr: Optional[np.ndarray] = None,
|
|
304
|
+
label: Optional[str] = None,
|
|
305
|
+
color: Optional[Union[str, tuple]] = None,
|
|
306
|
+
color_idx: Optional[int] = None,
|
|
307
|
+
linewidth: float = 2,
|
|
308
|
+
capsize: float = 3,
|
|
309
|
+
fmt: str = "o",
|
|
310
|
+
ax=None,
|
|
311
|
+
**kwargs,
|
|
312
|
+
):
|
|
313
|
+
"""Plot error bars with automatic color cycling and styling.
|
|
314
|
+
|
|
315
|
+
Parameters
|
|
316
|
+
----------
|
|
317
|
+
x, y : array-like
|
|
318
|
+
Data points
|
|
319
|
+
yerr, xerr : array-like, optional
|
|
320
|
+
Error values
|
|
321
|
+
label : str, optional
|
|
322
|
+
Label for legend
|
|
323
|
+
color : str or tuple, optional
|
|
324
|
+
Plot color
|
|
325
|
+
color_idx : int, optional
|
|
326
|
+
Index into color palette
|
|
327
|
+
linewidth : float
|
|
328
|
+
Line width
|
|
329
|
+
capsize : float
|
|
330
|
+
Cap size for error bars
|
|
331
|
+
fmt : str
|
|
332
|
+
Format string for markers/lines
|
|
333
|
+
ax : Axes, optional
|
|
334
|
+
Axis to plot on. If None, uses current axis.
|
|
335
|
+
**kwargs
|
|
336
|
+
Additional arguments passed to errorbar
|
|
337
|
+
"""
|
|
338
|
+
if ax is None:
|
|
339
|
+
ax = gca()
|
|
340
|
+
|
|
341
|
+
style = get_style()
|
|
342
|
+
return style.errorbar_styled(
|
|
343
|
+
ax=ax,
|
|
344
|
+
x=x,
|
|
345
|
+
y=y,
|
|
346
|
+
yerr=yerr,
|
|
347
|
+
xerr=xerr,
|
|
348
|
+
label=label,
|
|
349
|
+
color=color,
|
|
350
|
+
color_idx=color_idx,
|
|
351
|
+
linewidth=linewidth,
|
|
352
|
+
capsize=capsize,
|
|
353
|
+
fmt=fmt,
|
|
354
|
+
**kwargs,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def bar_styled(
|
|
359
|
+
x: Union[List, np.ndarray],
|
|
360
|
+
height: Union[List, np.ndarray],
|
|
361
|
+
label: Optional[str] = None,
|
|
362
|
+
color: Optional[Union[str, tuple]] = None,
|
|
363
|
+
color_idx: Optional[int] = None,
|
|
364
|
+
edgecolor: str = "black",
|
|
365
|
+
linewidth: float = 1,
|
|
366
|
+
ax=None,
|
|
367
|
+
**kwargs,
|
|
368
|
+
):
|
|
369
|
+
"""Plot bar chart with automatic color cycling and styling.
|
|
370
|
+
|
|
371
|
+
Parameters
|
|
372
|
+
----------
|
|
373
|
+
x : array-like
|
|
374
|
+
x-coordinates of the bars
|
|
375
|
+
height : array-like
|
|
376
|
+
Heights of the bars
|
|
377
|
+
label : str, optional
|
|
378
|
+
Label for the legend
|
|
379
|
+
color : str or tuple, optional
|
|
380
|
+
Bar color
|
|
381
|
+
color_idx : int, optional
|
|
382
|
+
Index into the palette
|
|
383
|
+
edgecolor : str
|
|
384
|
+
Color of bar edges
|
|
385
|
+
linewidth : float
|
|
386
|
+
Width of bar edges
|
|
387
|
+
ax : Axes, optional
|
|
388
|
+
Axis to plot on. If None, uses current axis.
|
|
389
|
+
**kwargs
|
|
390
|
+
Additional arguments passed to bar
|
|
391
|
+
"""
|
|
392
|
+
if ax is None:
|
|
393
|
+
ax = gca()
|
|
394
|
+
|
|
395
|
+
style = get_style()
|
|
396
|
+
return style.bar_styled(
|
|
397
|
+
ax=ax,
|
|
398
|
+
x=x,
|
|
399
|
+
height=height,
|
|
400
|
+
label=label,
|
|
401
|
+
color=color,
|
|
402
|
+
color_idx=color_idx,
|
|
403
|
+
edgecolor=edgecolor,
|
|
404
|
+
linewidth=linewidth,
|
|
405
|
+
**kwargs,
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
def hist_styled(
|
|
410
|
+
x: np.ndarray,
|
|
411
|
+
bins: Optional[Union[int, np.ndarray]] = None,
|
|
412
|
+
label: Optional[str] = None,
|
|
413
|
+
color: Optional[Union[str, tuple]] = None,
|
|
414
|
+
color_idx: Optional[int] = None,
|
|
415
|
+
edgecolor: str = "white",
|
|
416
|
+
alpha: float = 0.8,
|
|
417
|
+
ax=None,
|
|
418
|
+
**kwargs,
|
|
419
|
+
):
|
|
420
|
+
"""Plot histogram with automatic color cycling and styling.
|
|
421
|
+
|
|
422
|
+
Parameters
|
|
423
|
+
----------
|
|
424
|
+
x : array-like
|
|
425
|
+
Data to histogram
|
|
426
|
+
bins : int or array-like, optional
|
|
427
|
+
Number of bins or bin edges
|
|
428
|
+
label : str, optional
|
|
429
|
+
Label for the legend
|
|
430
|
+
color : str or tuple, optional
|
|
431
|
+
Histogram color
|
|
432
|
+
color_idx : int, optional
|
|
433
|
+
Index into the palette
|
|
434
|
+
edgecolor : str
|
|
435
|
+
Color of bin edges
|
|
436
|
+
alpha : float
|
|
437
|
+
Transparency
|
|
438
|
+
ax : Axes, optional
|
|
439
|
+
Axis to plot on. If None, uses current axis.
|
|
440
|
+
**kwargs
|
|
441
|
+
Additional arguments passed to hist
|
|
442
|
+
"""
|
|
443
|
+
if ax is None:
|
|
444
|
+
ax = gca()
|
|
445
|
+
|
|
446
|
+
style = get_style()
|
|
447
|
+
return style.hist_styled(
|
|
448
|
+
ax=ax,
|
|
449
|
+
x=x,
|
|
450
|
+
bins=bins,
|
|
451
|
+
label=label,
|
|
452
|
+
color=color,
|
|
453
|
+
color_idx=color_idx,
|
|
454
|
+
edgecolor=edgecolor,
|
|
455
|
+
alpha=alpha,
|
|
456
|
+
**kwargs,
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
def add_reference_line(
|
|
461
|
+
horizontal: Optional[Union[float, List[float]]] = None,
|
|
462
|
+
vertical: Optional[Union[float, List[float]]] = None,
|
|
463
|
+
color: str = "k",
|
|
464
|
+
linestyle: str = "--",
|
|
465
|
+
linewidth: float = 0.5,
|
|
466
|
+
alpha: float = 0.3,
|
|
467
|
+
label: Optional[str] = None,
|
|
468
|
+
ax=None,
|
|
469
|
+
):
|
|
470
|
+
"""Add reference lines to current axis.
|
|
471
|
+
|
|
472
|
+
Parameters
|
|
473
|
+
----------
|
|
474
|
+
horizontal : float or list, optional
|
|
475
|
+
y-values for horizontal lines
|
|
476
|
+
vertical : float or list, optional
|
|
477
|
+
x-values for vertical lines
|
|
478
|
+
color, linestyle, linewidth, alpha :
|
|
479
|
+
Line style parameters
|
|
480
|
+
label : str, optional
|
|
481
|
+
Label for legend
|
|
482
|
+
ax : Axes, optional
|
|
483
|
+
Axis to add lines to. If None, uses current axis.
|
|
484
|
+
"""
|
|
485
|
+
if ax is None:
|
|
486
|
+
ax = gca()
|
|
487
|
+
|
|
488
|
+
style = get_style()
|
|
489
|
+
style.add_reference_line(
|
|
490
|
+
ax=ax,
|
|
491
|
+
horizontal=horizontal,
|
|
492
|
+
vertical=vertical,
|
|
493
|
+
color=color,
|
|
494
|
+
linestyle=linestyle,
|
|
495
|
+
linewidth=linewidth,
|
|
496
|
+
alpha=alpha,
|
|
497
|
+
label=label,
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def add_highlight_region(
|
|
502
|
+
xmin: Optional[float] = None,
|
|
503
|
+
xmax: Optional[float] = None,
|
|
504
|
+
ymin: Optional[float] = None,
|
|
505
|
+
ymax: Optional[float] = None,
|
|
506
|
+
color: str = "0.85",
|
|
507
|
+
alpha: float = 0.5,
|
|
508
|
+
label: Optional[str] = None,
|
|
509
|
+
ax=None,
|
|
510
|
+
):
|
|
511
|
+
"""Add highlighted region to current axis.
|
|
512
|
+
|
|
513
|
+
Parameters
|
|
514
|
+
----------
|
|
515
|
+
xmin, xmax, ymin, ymax : float, optional
|
|
516
|
+
Region boundaries
|
|
517
|
+
color : str
|
|
518
|
+
Region color
|
|
519
|
+
alpha : float
|
|
520
|
+
Transparency
|
|
521
|
+
label : str, optional
|
|
522
|
+
Label for legend
|
|
523
|
+
ax : Axes, optional
|
|
524
|
+
Axis to add region to. If None, uses current axis.
|
|
525
|
+
"""
|
|
526
|
+
if ax is None:
|
|
527
|
+
ax = gca()
|
|
528
|
+
|
|
529
|
+
style = get_style()
|
|
530
|
+
style.add_highlight_region(
|
|
531
|
+
ax=ax,
|
|
532
|
+
xmin=xmin,
|
|
533
|
+
xmax=xmax,
|
|
534
|
+
ymin=ymin,
|
|
535
|
+
ymax=ymax,
|
|
536
|
+
color=color,
|
|
537
|
+
alpha=alpha,
|
|
538
|
+
label=label,
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
def format_legend(
|
|
543
|
+
loc: str = "best",
|
|
544
|
+
frameon: bool = True,
|
|
545
|
+
framealpha: float = 0.8,
|
|
546
|
+
ncol: int = 1,
|
|
547
|
+
ax=None,
|
|
548
|
+
**kwargs,
|
|
549
|
+
):
|
|
550
|
+
"""Format legend with consistent styling.
|
|
551
|
+
|
|
552
|
+
Parameters
|
|
553
|
+
----------
|
|
554
|
+
loc : str
|
|
555
|
+
Legend location
|
|
556
|
+
frameon : bool
|
|
557
|
+
Whether to draw frame
|
|
558
|
+
framealpha : float
|
|
559
|
+
Frame transparency
|
|
560
|
+
ncol : int
|
|
561
|
+
Number of columns
|
|
562
|
+
ax : Axes, optional
|
|
563
|
+
Axis containing legend. If None, uses current axis.
|
|
564
|
+
**kwargs
|
|
565
|
+
Additional arguments passed to legend()
|
|
566
|
+
"""
|
|
567
|
+
if ax is None:
|
|
568
|
+
ax = gca()
|
|
569
|
+
|
|
570
|
+
style = get_style()
|
|
571
|
+
return style.format_legend(
|
|
572
|
+
ax=ax,
|
|
573
|
+
loc=loc,
|
|
574
|
+
frameon=frameon,
|
|
575
|
+
framealpha=framealpha,
|
|
576
|
+
ncol=ncol,
|
|
577
|
+
**kwargs,
|
|
578
|
+
)
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
# Auto-initialize with default settings when module is imported
|
|
582
|
+
initialize_style()
|