myplotlib 1.4.0__tar.gz → 1.5.0__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.
- {myplotlib-1.4.0 → myplotlib-1.5.0}/PKG-INFO +25 -8
- {myplotlib-1.4.0 → myplotlib-1.5.0}/README.md +24 -7
- myplotlib-1.5.0/myplotlib/__init__.py +76 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/plots.py +113 -2
- {myplotlib-1.4.0 → myplotlib-1.5.0}/previews/README.md +6 -2
- {myplotlib-1.4.0 → myplotlib-1.5.0}/previews/export_previews.py +10 -9
- myplotlib-1.5.0/previews/fancy_dark.jpg +0 -0
- myplotlib-1.5.0/previews/fancy_light.jpg +0 -0
- myplotlib-1.5.0/previews/hershey_dark.jpg +0 -0
- myplotlib-1.5.0/previews/hershey_light.jpg +0 -0
- myplotlib-1.5.0/previews/latex.jpg +0 -0
- myplotlib-1.5.0/previews/mono_dark.jpg +0 -0
- myplotlib-1.5.0/previews/mono_light.jpg +0 -0
- myplotlib-1.5.0/previews/plain.jpg +0 -0
- myplotlib-1.4.0/myplotlib/__init__.py +0 -85
- myplotlib-1.4.0/previews/None.jpg +0 -0
- myplotlib-1.4.0/previews/fancy_dark.jpg +0 -0
- myplotlib-1.4.0/previews/fancy_light.jpg +0 -0
- myplotlib-1.4.0/previews/hershey_dark.jpg +0 -0
- myplotlib-1.4.0/previews/hershey_light.jpg +0 -0
- myplotlib-1.4.0/previews/mono_dark.jpg +0 -0
- myplotlib-1.4.0/previews/mono_light.jpg +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/.github/workflows/pypi-publish.yml +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/.gitignore +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/LICENSE +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/MANIFEST.in +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/colormaps/bipolar.csv +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/colormaps/colt.csv +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/colormaps/fire.csv +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/colormaps/idl.csv +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/colormaps/sunrise.csv +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/colormaps/thermal.csv +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/colormaps/vanilla.csv +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fancy.dark.mplstyle +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fancy.light.mplstyle +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/AppleChancery.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-Bold.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-BoldItalic.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-ExtraBold.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-ExtraBoldItalic.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-Italic.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-Medium.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-MediumItalic.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-Regular.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-SemiBold.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/EBGaramond-SemiBoldItalic.ttf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/HersheyTex-Book.otf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/fonts/HersheyTex-Light.otf +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/hershey.dark.mplstyle +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/hershey.light.mplstyle +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/latex.mplstyle +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/mono.dark.mplstyle +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/assets/mono.light.mplstyle +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/tests.py +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/tools/__init__.py +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/myplotlib/tools/lic.py +0 -0
- {myplotlib-1.4.0 → myplotlib-1.5.0}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: myplotlib
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.5.0
|
|
4
4
|
Summary: `matplotlib` binder with custom styles and routines for fast plotting
|
|
5
5
|
Project-URL: Repository, https://github.com/haykh/myplotlib
|
|
6
6
|
Author-email: Hayk <haykh.astro@gmail.com>
|
|
@@ -64,20 +64,37 @@ pip install myplotlib
|
|
|
64
64
|
|
|
65
65
|
### usage
|
|
66
66
|
|
|
67
|
+
#### loading style, fonts & colormaps
|
|
68
|
+
|
|
67
69
|
```python
|
|
68
|
-
# initialize style:
|
|
69
70
|
import myplotlib
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
#
|
|
74
|
-
#
|
|
71
|
+
import matplotlib.pyplot as plt
|
|
72
|
+
|
|
73
|
+
plt.style.use(STYLE)
|
|
74
|
+
# STYLE can be:
|
|
75
|
+
# - fancy.dark, fancy.light
|
|
76
|
+
# - hershey.dark, hershey.light
|
|
77
|
+
# - mono.dark, mono.light
|
|
78
|
+
# - latex
|
|
79
|
+
|
|
80
|
+
# you may also combine the styles:
|
|
81
|
+
plt.style.use([STYLE1, STYLE2])
|
|
82
|
+
|
|
83
|
+
# and you can temporarily load the style:
|
|
84
|
+
with plt.style.context(STYLE):
|
|
85
|
+
plt.plot(...)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### auxiliary plotting functions
|
|
75
89
|
|
|
76
|
-
|
|
90
|
+
```python
|
|
77
91
|
import myplotlib.plots as myplt
|
|
78
92
|
# type for docstring:
|
|
79
93
|
myplt?
|
|
80
94
|
|
|
95
|
+
# for specific function:
|
|
96
|
+
myplt.plot2d?
|
|
97
|
+
|
|
81
98
|
# preview custom styles with built-in functions
|
|
82
99
|
import myplotlib.tests as mypltest
|
|
83
100
|
# type for docstring:
|
|
@@ -10,20 +10,37 @@ pip install myplotlib
|
|
|
10
10
|
|
|
11
11
|
### usage
|
|
12
12
|
|
|
13
|
+
#### loading style, fonts & colormaps
|
|
14
|
+
|
|
13
15
|
```python
|
|
14
|
-
# initialize style:
|
|
15
16
|
import myplotlib
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
#
|
|
20
|
-
#
|
|
17
|
+
import matplotlib.pyplot as plt
|
|
18
|
+
|
|
19
|
+
plt.style.use(STYLE)
|
|
20
|
+
# STYLE can be:
|
|
21
|
+
# - fancy.dark, fancy.light
|
|
22
|
+
# - hershey.dark, hershey.light
|
|
23
|
+
# - mono.dark, mono.light
|
|
24
|
+
# - latex
|
|
25
|
+
|
|
26
|
+
# you may also combine the styles:
|
|
27
|
+
plt.style.use([STYLE1, STYLE2])
|
|
28
|
+
|
|
29
|
+
# and you can temporarily load the style:
|
|
30
|
+
with plt.style.context(STYLE):
|
|
31
|
+
plt.plot(...)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### auxiliary plotting functions
|
|
21
35
|
|
|
22
|
-
|
|
36
|
+
```python
|
|
23
37
|
import myplotlib.plots as myplt
|
|
24
38
|
# type for docstring:
|
|
25
39
|
myplt?
|
|
26
40
|
|
|
41
|
+
# for specific function:
|
|
42
|
+
myplt.plot2d?
|
|
43
|
+
|
|
27
44
|
# preview custom styles with built-in functions
|
|
28
45
|
import myplotlib.tests as mypltest
|
|
29
46
|
# type for docstring:
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
__version__ = "1.5.0"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
from matplotlib import font_manager
|
|
7
|
+
|
|
8
|
+
import myplotlib
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def __RGBToPyCmap(rgbdata):
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
nsteps = rgbdata.shape[0]
|
|
15
|
+
stepaxis = np.linspace(0, 1, nsteps)
|
|
16
|
+
rdata = []
|
|
17
|
+
gdata = []
|
|
18
|
+
bdata = []
|
|
19
|
+
for istep in range(nsteps):
|
|
20
|
+
r = rgbdata[istep, 0]
|
|
21
|
+
g = rgbdata[istep, 1]
|
|
22
|
+
b = rgbdata[istep, 2]
|
|
23
|
+
rdata.append((stepaxis[istep], r, r))
|
|
24
|
+
gdata.append((stepaxis[istep], g, g))
|
|
25
|
+
bdata.append((stepaxis[istep], b, b))
|
|
26
|
+
mpl_data = {"red": rdata, "green": gdata, "blue": bdata}
|
|
27
|
+
return mpl_data
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
CUSTOM_CMAPS = []
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def __InstallCmapFromCSV(csv):
|
|
34
|
+
global CUSTOM_CMAPS
|
|
35
|
+
import os
|
|
36
|
+
import numpy as np
|
|
37
|
+
import matplotlib as mpl
|
|
38
|
+
|
|
39
|
+
cmap = os.path.splitext(os.path.basename(csv))[0]
|
|
40
|
+
cmap_data = np.loadtxt(csv, delimiter=",")
|
|
41
|
+
if cmap not in mpl.colormaps.keys():
|
|
42
|
+
CUSTOM_CMAPS.append(cmap)
|
|
43
|
+
mpl_data = __RGBToPyCmap(cmap_data)
|
|
44
|
+
mpl.colormaps.register(
|
|
45
|
+
cmap=mpl.colors.LinearSegmentedColormap(cmap, mpl_data, cmap_data.shape[0])
|
|
46
|
+
)
|
|
47
|
+
cmap = f"{cmap}_r"
|
|
48
|
+
if cmap not in mpl.colormaps.keys():
|
|
49
|
+
mpl_data_r = __RGBToPyCmap(cmap_data[::-1, :])
|
|
50
|
+
mpl.colormaps.register(
|
|
51
|
+
cmap=mpl.colors.LinearSegmentedColormap(
|
|
52
|
+
cmap, mpl_data_r, cmap_data.shape[0]
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
myplotlib_path = myplotlib.__path__[0]
|
|
58
|
+
styles_path = os.path.join(myplotlib_path, "assets")
|
|
59
|
+
|
|
60
|
+
stylesheets = {}
|
|
61
|
+
for folder, _, _ in os.walk(styles_path):
|
|
62
|
+
new_stylesheets = plt.style.core.read_style_directory(folder)
|
|
63
|
+
stylesheets.update(new_stylesheets)
|
|
64
|
+
|
|
65
|
+
plt.style.core.update_nested_dict(plt.style.library, stylesheets)
|
|
66
|
+
plt.style.core.available[:] = sorted(plt.style.library.keys())
|
|
67
|
+
|
|
68
|
+
CMAP_DIR = os.path.join(myplotlib_path, "assets/colormaps")
|
|
69
|
+
CMAPS = os.listdir(CMAP_DIR)
|
|
70
|
+
for cmap in CMAPS:
|
|
71
|
+
cmapname = os.path.join(CMAP_DIR, cmap)
|
|
72
|
+
__InstallCmapFromCSV(cmapname)
|
|
73
|
+
FONT_DIR = os.path.join(myplotlib_path, "assets/fonts")
|
|
74
|
+
font_files = font_manager.findSystemFonts(fontpaths=[FONT_DIR])
|
|
75
|
+
for font_file in font_files:
|
|
76
|
+
font_manager.fontManager.addfont(font_file)
|
|
@@ -247,8 +247,11 @@ def plot2d(
|
|
|
247
247
|
if cbar is not None:
|
|
248
248
|
divider = make_axes_locatable(ax)
|
|
249
249
|
cax = divider.append_axes(cbar_pos, size=cbar, pad=cbar_pad)
|
|
250
|
-
colorbar = plt.colorbar(
|
|
251
|
-
|
|
250
|
+
colorbar = plt.colorbar(
|
|
251
|
+
ax.get_images()[0],
|
|
252
|
+
cax=cax,
|
|
253
|
+
orientation="vertical" if cbar_pos in ["left", "right"] else "horizontal",
|
|
254
|
+
)
|
|
252
255
|
if cbar_pos == "left":
|
|
253
256
|
cax.yaxis.set_ticks_position("left")
|
|
254
257
|
cax.yaxis.set_label_position("left")
|
|
@@ -387,3 +390,111 @@ def plotVectorField(
|
|
|
387
390
|
alpha=lic_opacity,
|
|
388
391
|
)
|
|
389
392
|
return colorbar
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def plot2dGrid(
|
|
396
|
+
x,
|
|
397
|
+
y,
|
|
398
|
+
fields,
|
|
399
|
+
panels,
|
|
400
|
+
label_pos="title",
|
|
401
|
+
label_args={},
|
|
402
|
+
width=10,
|
|
403
|
+
dpi=150,
|
|
404
|
+
wspace=0.05,
|
|
405
|
+
hspace=0.05,
|
|
406
|
+
**kwargs,
|
|
407
|
+
):
|
|
408
|
+
"""
|
|
409
|
+
add a grid of 2d plots with shared axes
|
|
410
|
+
|
|
411
|
+
args
|
|
412
|
+
----------
|
|
413
|
+
x, y ........................ : 1d or 2d arrays of coordinates
|
|
414
|
+
fields ...................... : dictionary of all the fields
|
|
415
|
+
panels ...................... : array of array of dictionaries indicating the panels to plot (see note below)
|
|
416
|
+
label_pos ['title'] ......... : position of the label ('title', 'cbar', 'text', None)
|
|
417
|
+
label_args [{}] ............. : arguments for the label (color, fontsize, etc; passed to `ax.set_title`, )
|
|
418
|
+
|
|
419
|
+
arguments for the figure
|
|
420
|
+
----------
|
|
421
|
+
width [10] .................. : width of the figure in inches
|
|
422
|
+
dpi [150] ................... : resolution of the figure [dots per inch]
|
|
423
|
+
wspace [0.05] ............... : width space between the panels (as fraction of the panel width)
|
|
424
|
+
hspace [0.05] ............... : height space between the panels (as fraction of the panel height)
|
|
425
|
+
|
|
426
|
+
the rest of the args are the same as for the `plot2d`
|
|
427
|
+
----------
|
|
428
|
+
force_aspect [True] ......... : force equal aspect ratio according to axes
|
|
429
|
+
centering ['edge'] .......... : centering of x & y nodes for the data ('edge', 'center')
|
|
430
|
+
xlim [None], ylim [None] .... : tuples of x and y limits (None = determine from x & y)
|
|
431
|
+
padx [0], pady [0] .......... : add whitespace to axes in each direction (0 = no additional space)
|
|
432
|
+
cbar ['5%'] ................. : size of the colorbar in percent of x-axis (None = no colorbar)
|
|
433
|
+
cbar_pad [0.05] ............. : padding of the colorbar
|
|
434
|
+
**kwargs .................... : standard matplotlib kwargs passed to `ax.imshow`
|
|
435
|
+
|
|
436
|
+
note
|
|
437
|
+
----------
|
|
438
|
+
the `panels` is an `n x m` array, where `n` is the number of rows and `m` is the number of columns.
|
|
439
|
+
each element of the array is a dictionary with the following keys:
|
|
440
|
+
- 'label' ............... : label for the field
|
|
441
|
+
- 'field' ............... : lambda function which takes the `fields` dictionary and returns the quantity to plot
|
|
442
|
+
- 'cmap' ................ : colormap of the panel
|
|
443
|
+
- 'norm' ................ : normalization object
|
|
444
|
+
"""
|
|
445
|
+
import matplotlib.pyplot as plt
|
|
446
|
+
|
|
447
|
+
assert len(panels) > 0, "no panels to plot"
|
|
448
|
+
assert len(panels[0]) > 0, "no panels to plot"
|
|
449
|
+
assert all(
|
|
450
|
+
[len(row) == len(panels[0]) for row in panels]
|
|
451
|
+
), "all rows must have the same number of panels"
|
|
452
|
+
assert label_pos in ["title", "cbar", "text", None], "invalid label position"
|
|
453
|
+
|
|
454
|
+
ncols = len(panels[0])
|
|
455
|
+
nrows = len(panels)
|
|
456
|
+
|
|
457
|
+
xlims = kwargs.get("xlim", (x.min(), x.max()))
|
|
458
|
+
ylims = kwargs.get("ylim", (y.min(), y.max()))
|
|
459
|
+
aspect = (xlims[1] - xlims[0]) / (ylims[1] - ylims[0])
|
|
460
|
+
height = (
|
|
461
|
+
width
|
|
462
|
+
* ((nrows + hspace * (nrows - 1)) / (ncols + wspace * (ncols - 1)))
|
|
463
|
+
/ aspect
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
fig = plt.figure(figsize=(width, height), dpi=dpi)
|
|
467
|
+
|
|
468
|
+
gs = fig.add_gridspec(nrows, ncols, wspace=wspace, hspace=hspace)
|
|
469
|
+
axs = [[fig.add_subplot(gs[i, j]) for j in range(ncols)] for i in range(nrows)]
|
|
470
|
+
|
|
471
|
+
label_coords = label_args.pop("position", (0.05, 0.95))
|
|
472
|
+
|
|
473
|
+
for i in range(nrows):
|
|
474
|
+
for j in range(ncols):
|
|
475
|
+
ax = axs[i][j]
|
|
476
|
+
panel = panels[i][j]
|
|
477
|
+
|
|
478
|
+
cbar = plot2d(
|
|
479
|
+
ax,
|
|
480
|
+
x,
|
|
481
|
+
y,
|
|
482
|
+
panel["field"](fields),
|
|
483
|
+
norm=panel["norm"],
|
|
484
|
+
cmap=panel["cmap"],
|
|
485
|
+
**kwargs,
|
|
486
|
+
)
|
|
487
|
+
|
|
488
|
+
if j != 0:
|
|
489
|
+
ax.set(ylabel=None, yticklabels=[])
|
|
490
|
+
if i != nrows - 1:
|
|
491
|
+
ax.set(xlabel=None, xticklabels=[])
|
|
492
|
+
|
|
493
|
+
if label_pos == "title":
|
|
494
|
+
ax.set_title(panel["label"], **label_args)
|
|
495
|
+
elif label_pos == "cbar":
|
|
496
|
+
cbar.set_label(panel["label"], **label_args)
|
|
497
|
+
elif label_pos == "text":
|
|
498
|
+
ax.text(
|
|
499
|
+
*label_coords, panel["label"], transform=ax.transAxes, **label_args
|
|
500
|
+
)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import matplotlib as mpl
|
|
3
2
|
import matplotlib.pyplot as plt
|
|
4
3
|
|
|
5
4
|
import myplotlib
|
|
@@ -13,17 +12,19 @@ if __name__ == "__main__":
|
|
|
13
12
|
for f in os.listdir("myplotlib/assets")
|
|
14
13
|
if f.endswith(".mplstyle") and f.count(".") == 2
|
|
15
14
|
]:
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
with plt.style.context(f"{st}.{fl}"):
|
|
16
|
+
mypltests.testAll()
|
|
17
|
+
plt.savefig(f"previews/{st}_{fl}.jpg")
|
|
18
|
+
readme += f"# `{st}.{fl}`\n\n\n\n"
|
|
19
|
+
|
|
20
|
+
with plt.style.context("latex"):
|
|
18
21
|
mypltests.testAll()
|
|
19
|
-
plt.savefig(f"previews/
|
|
20
|
-
readme += f"# `
|
|
22
|
+
plt.savefig(f"previews/latex.jpg")
|
|
23
|
+
readme += f"# `Latex`\n\n\n\n"
|
|
21
24
|
|
|
22
|
-
mpl.rcParams.update(mpl.rcParamsDefault)
|
|
23
|
-
myplotlib.load(None, None)
|
|
24
25
|
mypltests.testAll()
|
|
25
|
-
plt.savefig(f"previews/
|
|
26
|
-
readme += f"# `
|
|
26
|
+
plt.savefig(f"previews/plain.jpg")
|
|
27
|
+
readme += f"# `Plain`\n\n\n\n"
|
|
27
28
|
|
|
28
29
|
with open("previews/README.md", "w") as f:
|
|
29
30
|
f.write(readme)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
__version__ = "1.4.0"
|
|
2
|
-
|
|
3
|
-
CUSTOM_CMAPS = []
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def __RGBToPyCmap(rgbdata):
|
|
7
|
-
import numpy as np
|
|
8
|
-
|
|
9
|
-
nsteps = rgbdata.shape[0]
|
|
10
|
-
stepaxis = np.linspace(0, 1, nsteps)
|
|
11
|
-
rdata = []
|
|
12
|
-
gdata = []
|
|
13
|
-
bdata = []
|
|
14
|
-
for istep in range(nsteps):
|
|
15
|
-
r = rgbdata[istep, 0]
|
|
16
|
-
g = rgbdata[istep, 1]
|
|
17
|
-
b = rgbdata[istep, 2]
|
|
18
|
-
rdata.append((stepaxis[istep], r, r))
|
|
19
|
-
gdata.append((stepaxis[istep], g, g))
|
|
20
|
-
bdata.append((stepaxis[istep], b, b))
|
|
21
|
-
mpl_data = {"red": rdata, "green": gdata, "blue": bdata}
|
|
22
|
-
return mpl_data
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def __InstallCmapFromCSV(csv):
|
|
26
|
-
global CUSTOM_CMAPS
|
|
27
|
-
import os
|
|
28
|
-
import numpy as np
|
|
29
|
-
import matplotlib as mpl
|
|
30
|
-
|
|
31
|
-
cmap = os.path.splitext(os.path.basename(csv))[0]
|
|
32
|
-
cmap_data = np.loadtxt(csv, delimiter=",")
|
|
33
|
-
if cmap not in mpl.colormaps.keys():
|
|
34
|
-
CUSTOM_CMAPS.append(cmap)
|
|
35
|
-
mpl_data = __RGBToPyCmap(cmap_data)
|
|
36
|
-
mpl.colormaps.register(
|
|
37
|
-
cmap=mpl.colors.LinearSegmentedColormap(cmap, mpl_data, cmap_data.shape[0])
|
|
38
|
-
)
|
|
39
|
-
cmap = f"{cmap}_r"
|
|
40
|
-
if cmap not in mpl.colormaps.keys():
|
|
41
|
-
mpl_data_r = __RGBToPyCmap(cmap_data[::-1, :])
|
|
42
|
-
mpl.colormaps.register(
|
|
43
|
-
cmap=mpl.colors.LinearSegmentedColormap(
|
|
44
|
-
cmap, mpl_data_r, cmap_data.shape[0]
|
|
45
|
-
)
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def load(style=None, flavor="light", usetex=True):
|
|
50
|
-
"""
|
|
51
|
-
`myplotlib.load`
|
|
52
|
-
|
|
53
|
-
preload custom style
|
|
54
|
-
|
|
55
|
-
args
|
|
56
|
-
----------
|
|
57
|
-
style [None] ............. : style to load (options: None, 'fancy', 'mono', 'hershey')
|
|
58
|
-
flavor ['light'] ......... : color flavor to load (options: 'light', 'dark')
|
|
59
|
-
usetex [True] ............ : whether to use LaTeX (True/False)
|
|
60
|
-
"""
|
|
61
|
-
import os
|
|
62
|
-
from matplotlib import font_manager
|
|
63
|
-
import matplotlib.pyplot as plt
|
|
64
|
-
|
|
65
|
-
assert usetex or style != "fancy", "fancy style requires usetex=True"
|
|
66
|
-
|
|
67
|
-
CMAP_DIR = os.path.join(os.path.dirname(__file__), "assets/colormaps")
|
|
68
|
-
CMAPS = os.listdir(CMAP_DIR)
|
|
69
|
-
for cmap in CMAPS:
|
|
70
|
-
cmapname = os.path.join(CMAP_DIR, cmap)
|
|
71
|
-
__InstallCmapFromCSV(cmapname)
|
|
72
|
-
FONT_DIR = os.path.join(os.path.dirname(__file__), "assets/fonts")
|
|
73
|
-
font_files = font_manager.findSystemFonts(fontpaths=[FONT_DIR])
|
|
74
|
-
for font_file in font_files:
|
|
75
|
-
font_manager.fontManager.addfont(font_file)
|
|
76
|
-
if style is not None:
|
|
77
|
-
MPLSTYLE_FILE = os.path.join(
|
|
78
|
-
os.path.dirname(__file__), f"assets/{style}.{flavor}.mplstyle"
|
|
79
|
-
)
|
|
80
|
-
plt.style.use(MPLSTYLE_FILE)
|
|
81
|
-
if usetex and not style == "fancy":
|
|
82
|
-
LATEXSTILE_FILE = os.path.join(
|
|
83
|
-
os.path.dirname(__file__), f"assets/latex.mplstyle"
|
|
84
|
-
)
|
|
85
|
-
plt.style.use(LATEXSTILE_FILE)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
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
|
|
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
|