chemparseplot 1.13.2__py3-none-any.whl → 1.14.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.
- _version.py +2 -2
- chemparseplot/plot/chemgp.py +255 -149
- chemparseplot/plot/journal.py +1113 -0
- chemparseplot/plot/landscape.py +6 -1
- chemparseplot/plot/neb.py +342 -66
- chemparseplot/plot/optimization.py +179 -33
- chemparseplot/plot/palette.py +806 -0
- chemparseplot/plot/reaction.py +14 -4
- chemparseplot/plot/theme.py +31 -32
- {chemparseplot-1.13.2.dist-info → chemparseplot-1.14.1.dist-info}/METADATA +54 -63
- {chemparseplot-1.13.2.dist-info → chemparseplot-1.14.1.dist-info}/RECORD +28 -11
- tests/plot/data/au_al100.json +19729 -0
- tests/plot/data/au_al100.py +350 -0
- tests/plot/data/figures/convergence.png +0 -0
- tests/plot/data/figures/energy_landscape.png +0 -0
- tests/plot/data/figures/neb_profile.png +0 -0
- tests/plot/data/figures/neb_profile_history.png +0 -0
- tests/plot/data/figures/relative_error.png +0 -0
- tests/plot/data/figures/versions.json +4 -0
- tests/plot/test_chemgp_imports.py +49 -0
- tests/plot/test_figure_images.py +206 -0
- tests/plot/test_journal.py +560 -0
- tests/plot/test_journal_plots.py +295 -0
- tests/plot/test_palette.py +332 -0
- tests/plot/test_theme.py +107 -0
- tests/tutorials/test_journal_figure.py +50 -0
- {chemparseplot-1.13.2.dist-info → chemparseplot-1.14.1.dist-info}/WHEEL +0 -0
- {chemparseplot-1.13.2.dist-info → chemparseplot-1.14.1.dist-info}/licenses/LICENSE +0 -0
_version.py
CHANGED
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '1.
|
|
22
|
-
__version_tuple__ = version_tuple = (1,
|
|
21
|
+
__version__ = version = '1.14.1'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 14, 1)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
chemparseplot/plot/chemgp.py
CHANGED
|
@@ -6,40 +6,40 @@ convergence, surfaces, and diagnostics.
|
|
|
6
6
|
|
|
7
7
|
Surface plots use matplotlib contourf with the RUHI colormap,
|
|
8
8
|
matching the Julia CairoMakie originals. Line charts use plotnine
|
|
9
|
-
for ggplot2 grammar
|
|
9
|
+
for ggplot2 grammar; plotnine and pandas are imported when a line
|
|
10
|
+
chart is first drawn, so the surface plots need neither.
|
|
10
11
|
|
|
11
12
|
```{versionadded} 1.4.0
|
|
12
13
|
```
|
|
13
14
|
"""
|
|
14
15
|
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
15
18
|
import logging
|
|
16
19
|
from functools import lru_cache
|
|
20
|
+
from typing import TYPE_CHECKING
|
|
17
21
|
|
|
18
22
|
import matplotlib.patheffects as mpe
|
|
19
23
|
import matplotlib.pyplot as plt
|
|
20
24
|
import numpy as np
|
|
21
|
-
|
|
22
|
-
from
|
|
23
|
-
|
|
24
|
-
element_text,
|
|
25
|
-
facet_wrap,
|
|
26
|
-
geom_hline,
|
|
27
|
-
geom_line,
|
|
28
|
-
geom_point,
|
|
29
|
-
ggplot,
|
|
30
|
-
labs,
|
|
31
|
-
scale_color_manual,
|
|
32
|
-
scale_y_log10,
|
|
33
|
-
theme,
|
|
34
|
-
theme_minimal,
|
|
35
|
-
)
|
|
25
|
+
from matplotlib.cm import ScalarMappable
|
|
26
|
+
from matplotlib.colors import Normalize
|
|
27
|
+
from matplotlib.ticker import AutoLocator
|
|
36
28
|
|
|
29
|
+
from chemparseplot.plot.journal import DEFAULT_JOURNAL, apply_style, fit_height
|
|
30
|
+
from chemparseplot.plot.palette import RUHI_SEQUENTIAL, best_contrast
|
|
37
31
|
from chemparseplot.plot.theme import (
|
|
38
32
|
RUHI_COLORS,
|
|
39
33
|
get_theme,
|
|
40
34
|
setup_publication_theme,
|
|
41
35
|
)
|
|
42
36
|
|
|
37
|
+
if TYPE_CHECKING:
|
|
38
|
+
import pandas as pd
|
|
39
|
+
from plotnine import ggplot
|
|
40
|
+
|
|
41
|
+
from chemparseplot.plot.journal import JournalPreset
|
|
42
|
+
|
|
43
43
|
log = logging.getLogger(__name__)
|
|
44
44
|
|
|
45
45
|
# Ordered palette for method comparisons
|
|
@@ -51,16 +51,27 @@ _METHOD_PALETTE = [
|
|
|
51
51
|
RUHI_COLORS["sunshine"],
|
|
52
52
|
]
|
|
53
53
|
|
|
54
|
-
_JOST_THEME = theme_minimal() + theme(
|
|
55
|
-
text=element_text(family="Jost"),
|
|
56
|
-
plot_title=element_text(family="Jost", size=12),
|
|
57
|
-
axis_title=element_text(family="Jost", size=11),
|
|
58
|
-
strip_text=element_text(family="Jost", size=10),
|
|
59
|
-
)
|
|
60
|
-
|
|
61
54
|
_STROKE = [mpe.withStroke(linewidth=1.5, foreground="black")]
|
|
62
55
|
|
|
63
56
|
|
|
57
|
+
@lru_cache(maxsize=1)
|
|
58
|
+
def _gg():
|
|
59
|
+
import plotnine
|
|
60
|
+
|
|
61
|
+
return plotnine
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@lru_cache(maxsize=1)
|
|
65
|
+
def _jost_theme():
|
|
66
|
+
gg = _gg()
|
|
67
|
+
return gg.theme_minimal() + gg.theme(
|
|
68
|
+
text=gg.element_text(family="Jost"),
|
|
69
|
+
plot_title=gg.element_text(family="Jost", size=12),
|
|
70
|
+
axis_title=gg.element_text(family="Jost", size=11),
|
|
71
|
+
strip_text=gg.element_text(family="Jost", size=10),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
64
75
|
def _ensure_ruhi_cmap():
|
|
65
76
|
"""Ensure the ruhi_diverging colormap is registered."""
|
|
66
77
|
try:
|
|
@@ -141,6 +152,7 @@ def plot_convergence_curve(
|
|
|
141
152
|
|
|
142
153
|
.. versionadded:: 1.4.0
|
|
143
154
|
"""
|
|
155
|
+
gg = _gg()
|
|
144
156
|
methods = df[color].unique()
|
|
145
157
|
palette = dict(zip(methods, _METHOD_PALETTE, strict=False))
|
|
146
158
|
|
|
@@ -152,25 +164,25 @@ def plot_convergence_curve(
|
|
|
152
164
|
}.get(y, y)
|
|
153
165
|
|
|
154
166
|
p = (
|
|
155
|
-
ggplot(df, aes(x=x, y=y, color=color))
|
|
156
|
-
+ geom_line(size=0.9)
|
|
157
|
-
+ geom_point(size=1.5, alpha=0.7)
|
|
158
|
-
+ scale_color_manual(values=palette)
|
|
159
|
-
+ labs(
|
|
167
|
+
gg.ggplot(df, gg.aes(x=x, y=y, color=color))
|
|
168
|
+
+ gg.geom_line(size=0.9)
|
|
169
|
+
+ gg.geom_point(size=1.5, alpha=0.7)
|
|
170
|
+
+ gg.scale_color_manual(values=palette)
|
|
171
|
+
+ gg.labs(
|
|
160
172
|
x="Oracle calls",
|
|
161
173
|
y=y_label,
|
|
162
174
|
color="Method",
|
|
163
175
|
)
|
|
164
|
-
+
|
|
165
|
-
+ theme(figure_size=(width, height))
|
|
176
|
+
+ _jost_theme()
|
|
177
|
+
+ gg.theme(figure_size=(width, height))
|
|
166
178
|
)
|
|
167
179
|
if log_y:
|
|
168
|
-
p = p + scale_y_log10()
|
|
180
|
+
p = p + gg.scale_y_log10()
|
|
169
181
|
if conv_tol is not None:
|
|
170
182
|
if isinstance(conv_tol, dict):
|
|
171
183
|
for method_name, tol_val in conv_tol.items():
|
|
172
184
|
method_color = palette.get(method_name, "grey")
|
|
173
|
-
p = p + geom_hline(
|
|
185
|
+
p = p + gg.geom_hline(
|
|
174
186
|
yintercept=tol_val,
|
|
175
187
|
linetype="dashed",
|
|
176
188
|
color=method_color,
|
|
@@ -178,7 +190,7 @@ def plot_convergence_curve(
|
|
|
178
190
|
alpha=0.6,
|
|
179
191
|
)
|
|
180
192
|
else:
|
|
181
|
-
p = p + geom_hline(
|
|
193
|
+
p = p + gg.geom_hline(
|
|
182
194
|
yintercept=conv_tol,
|
|
183
195
|
linetype="dashed",
|
|
184
196
|
color="grey",
|
|
@@ -222,6 +234,9 @@ def plot_rff_quality(
|
|
|
222
234
|
|
|
223
235
|
.. versionadded:: 1.4.0
|
|
224
236
|
"""
|
|
237
|
+
import pandas as pd
|
|
238
|
+
|
|
239
|
+
gg = _gg()
|
|
225
240
|
e_df = (
|
|
226
241
|
df[["d_rff", "energy_mae"]]
|
|
227
242
|
.rename(columns={"energy_mae": "mae"})
|
|
@@ -242,20 +257,20 @@ def plot_rff_quality(
|
|
|
242
257
|
)
|
|
243
258
|
|
|
244
259
|
p = (
|
|
245
|
-
ggplot(long, aes(x="d_rff", y="mae"))
|
|
246
|
-
+ geom_line(color=RUHI_COLORS["teal"], size=0.9)
|
|
247
|
-
+ geom_point(color=RUHI_COLORS["teal"], size=1.5)
|
|
248
|
-
+ geom_hline(
|
|
260
|
+
gg.ggplot(long, gg.aes(x="d_rff", y="mae"))
|
|
261
|
+
+ gg.geom_line(color=RUHI_COLORS["teal"], size=0.9)
|
|
262
|
+
+ gg.geom_point(color=RUHI_COLORS["teal"], size=1.5)
|
|
263
|
+
+ gg.geom_hline(
|
|
249
264
|
data=baselines,
|
|
250
|
-
mapping=aes(yintercept="exact"),
|
|
265
|
+
mapping=gg.aes(yintercept="exact"),
|
|
251
266
|
linetype="dashed",
|
|
252
267
|
color=RUHI_COLORS["coral"],
|
|
253
268
|
size=0.5,
|
|
254
269
|
)
|
|
255
|
-
+ facet_wrap("metric", ncol=2, scales="free_y")
|
|
256
|
-
+ labs(x=r"$D_{\mathrm{RFF}}$", y="MAE")
|
|
257
|
-
+
|
|
258
|
-
+ theme(figure_size=(width, height))
|
|
270
|
+
+ gg.facet_wrap("metric", ncol=2, scales="free_y")
|
|
271
|
+
+ gg.labs(x=r"$D_{\mathrm{RFF}}$", y="MAE")
|
|
272
|
+
+ _jost_theme()
|
|
273
|
+
+ gg.theme(figure_size=(width, height))
|
|
259
274
|
)
|
|
260
275
|
return p
|
|
261
276
|
|
|
@@ -538,6 +553,9 @@ def plot_fps_projection(
|
|
|
538
553
|
|
|
539
554
|
.. versionadded:: 1.4.0
|
|
540
555
|
"""
|
|
556
|
+
import pandas as pd
|
|
557
|
+
|
|
558
|
+
gg = _gg()
|
|
541
559
|
sel_df = pd.DataFrame(
|
|
542
560
|
{
|
|
543
561
|
"pc1": np.asarray(selected_pc1),
|
|
@@ -560,12 +578,12 @@ def plot_fps_projection(
|
|
|
560
578
|
}
|
|
561
579
|
|
|
562
580
|
p = (
|
|
563
|
-
ggplot(all_df, aes(x="pc1", y="pc2", color="group"))
|
|
564
|
-
+ geom_point(size=1.5, alpha=0.7)
|
|
565
|
-
+ scale_color_manual(values=palette)
|
|
566
|
-
+ labs(x=r"$\mathrm{PC}_1$", y=r"$\mathrm{PC}_2$", color="")
|
|
567
|
-
+
|
|
568
|
-
+ theme(figure_size=(width, height))
|
|
581
|
+
gg.ggplot(all_df, gg.aes(x="pc1", y="pc2", color="group"))
|
|
582
|
+
+ gg.geom_point(size=1.5, alpha=0.7)
|
|
583
|
+
+ gg.scale_color_manual(values=palette)
|
|
584
|
+
+ gg.labs(x=r"$\mathrm{PC}_1$", y=r"$\mathrm{PC}_2$", color="")
|
|
585
|
+
+ _jost_theme()
|
|
586
|
+
+ gg.theme(figure_size=(width, height))
|
|
569
587
|
)
|
|
570
588
|
return p
|
|
571
589
|
|
|
@@ -607,21 +625,22 @@ def plot_energy_profile(
|
|
|
607
625
|
|
|
608
626
|
.. versionadded:: 1.4.0
|
|
609
627
|
"""
|
|
628
|
+
gg = _gg()
|
|
610
629
|
methods = df[color].unique()
|
|
611
630
|
palette = dict(zip(methods, _METHOD_PALETTE, strict=False))
|
|
612
631
|
|
|
613
632
|
p = (
|
|
614
|
-
ggplot(df, aes(x=x, y=y, color=color))
|
|
615
|
-
+ geom_line(size=0.9)
|
|
616
|
-
+ geom_point(size=2.0)
|
|
617
|
-
+ scale_color_manual(values=palette)
|
|
618
|
-
+ labs(
|
|
633
|
+
gg.ggplot(df, gg.aes(x=x, y=y, color=color))
|
|
634
|
+
+ gg.geom_line(size=0.9)
|
|
635
|
+
+ gg.geom_point(size=2.0)
|
|
636
|
+
+ gg.scale_color_manual(values=palette)
|
|
637
|
+
+ gg.labs(
|
|
619
638
|
x="Image index",
|
|
620
639
|
y=r"$\Delta E$ (eV)",
|
|
621
640
|
color="Method",
|
|
622
641
|
)
|
|
623
|
-
+
|
|
624
|
-
+ theme(figure_size=(width, height))
|
|
642
|
+
+ _jost_theme()
|
|
643
|
+
+ gg.theme(figure_size=(width, height))
|
|
625
644
|
)
|
|
626
645
|
return p
|
|
627
646
|
|
|
@@ -640,14 +659,26 @@ def plot_surface_contour(
|
|
|
640
659
|
levels: int | np.ndarray | None = None,
|
|
641
660
|
contour_step: float | None = None,
|
|
642
661
|
_point_style: str = "star",
|
|
643
|
-
width: float =
|
|
644
|
-
height: float =
|
|
662
|
+
width: float | None = None,
|
|
663
|
+
height: float | None = None,
|
|
664
|
+
*,
|
|
665
|
+
journal: str | JournalPreset | None = None,
|
|
666
|
+
columns: str = "single",
|
|
667
|
+
cmap: str | None = None,
|
|
668
|
+
xlabel: str = r"$x$",
|
|
669
|
+
ylabel: str = r"$y$",
|
|
670
|
+
zlabel: str = r"$E$ (eV)",
|
|
645
671
|
) -> plt.Figure:
|
|
646
672
|
"""2D filled contour with optional path and point overlays.
|
|
647
673
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
674
|
+
Drawn in the style of :mod:`chemparseplot.plot.journal`: one column of
|
|
675
|
+
``journal`` wide and as tall as the equal-aspect map needs, filled with
|
|
676
|
+
``ruhi_diverging``. Filled bands, contour lines and colour-bar ticks
|
|
677
|
+
share one set of levels, and each contour line is black or white,
|
|
678
|
+
whichever contrasts more with the bands on either side. Paths are white
|
|
679
|
+
lines with a dark outline through numbered sky-blue images. Minima are
|
|
680
|
+
white circles (A, B, ...), saddles white crosses (S1, S2, ...) and other
|
|
681
|
+
points sunshine stars.
|
|
651
682
|
|
|
652
683
|
Parameters
|
|
653
684
|
----------
|
|
@@ -662,13 +693,25 @@ def plot_surface_contour(
|
|
|
662
693
|
clamp_lo, clamp_hi : float or None
|
|
663
694
|
Value clamping for z data.
|
|
664
695
|
levels : int or array or None
|
|
665
|
-
Explicit contour levels. If None,
|
|
696
|
+
Explicit contour levels. If None, the levels are the ticks
|
|
697
|
+
matplotlib's automatic locator puts on the colour bar, which it
|
|
698
|
+
spaces by the tick font size, so every band edge is labelled.
|
|
666
699
|
contour_step : float or None
|
|
667
|
-
Step
|
|
700
|
+
Step between contour lines. If None, lines are drawn at the levels.
|
|
668
701
|
point_style : str
|
|
669
702
|
Default point style: "star" or "labeled".
|
|
670
|
-
width, height : float
|
|
671
|
-
Figure size in inches.
|
|
703
|
+
width, height : float or None
|
|
704
|
+
Figure size in inches. Default: the ``columns`` width of
|
|
705
|
+
``journal`` and the height the map needs at that width.
|
|
706
|
+
journal : str or JournalPreset or None
|
|
707
|
+
Journal whose style goes into the global rcParams, so the figure
|
|
708
|
+
saves in it (default ``"acs"``).
|
|
709
|
+
columns : str
|
|
710
|
+
Column span for the default width.
|
|
711
|
+
cmap : str or None
|
|
712
|
+
Colour map name (default ``"ruhi_diverging"``).
|
|
713
|
+
xlabel, ylabel, zlabel : str
|
|
714
|
+
Axis labels and colour-bar label.
|
|
672
715
|
|
|
673
716
|
Returns
|
|
674
717
|
-------
|
|
@@ -684,140 +727,203 @@ def plot_surface_contour(
|
|
|
684
727
|
>>> fig = plot_surface_contour(X, Y, Z, clamp_lo=-1, clamp_hi=1)
|
|
685
728
|
|
|
686
729
|
.. versionadded:: 1.4.0
|
|
730
|
+
|
|
731
|
+
.. versionchanged:: 1.14.0
|
|
732
|
+
Journal style and size by default, the ``ruhi_diverging`` map, shared
|
|
733
|
+
levels for bands, lines and colour bar; added *journal*,
|
|
734
|
+
*columns*, *cmap*, *xlabel*, *ylabel* and *zlabel*.
|
|
687
735
|
"""
|
|
688
|
-
|
|
736
|
+
_ensure_ruhi_cmap()
|
|
737
|
+
style = apply_style(journal or DEFAULT_JOURNAL, theme="ruhi")
|
|
738
|
+
cmap = cmap or "ruhi_diverging"
|
|
689
739
|
|
|
690
|
-
gz = np.asarray(grid_z).copy()
|
|
740
|
+
gz = np.asarray(grid_z, dtype=float).copy()
|
|
691
741
|
if clamp_lo is not None:
|
|
692
742
|
gz = np.clip(gz, clamp_lo, None)
|
|
693
743
|
if clamp_hi is not None:
|
|
694
744
|
gz = np.clip(gz, None, clamp_hi)
|
|
695
745
|
|
|
696
|
-
lo = clamp_lo if clamp_lo is not None else float(
|
|
697
|
-
hi = clamp_hi if clamp_hi is not None else float(
|
|
746
|
+
lo = clamp_lo if clamp_lo is not None else float(np.nanmin(gz))
|
|
747
|
+
hi = clamp_hi if clamp_hi is not None else float(np.nanmax(gz))
|
|
748
|
+
gx = np.asarray(grid_x, dtype=float)
|
|
749
|
+
gy = np.asarray(grid_y, dtype=float)
|
|
750
|
+
|
|
751
|
+
fig_w = style.width(columns) if width is None else width
|
|
752
|
+
fig_h = height
|
|
753
|
+
if fig_h is None:
|
|
754
|
+
fig_h = fig_w * np.ptp(gy) / np.ptp(gx)
|
|
755
|
+
if style.preset.max_height is not None:
|
|
756
|
+
fig_h = min(fig_h, style.preset.max_height)
|
|
757
|
+
fig, ax = plt.subplots(figsize=(fig_w, fig_h), layout="constrained")
|
|
758
|
+
ax.set_xlim(gx.min(), gx.max())
|
|
759
|
+
ax.set_ylim(gy.min(), gy.max())
|
|
760
|
+
ax.set_aspect("equal")
|
|
761
|
+
ax.set_xlabel(xlabel)
|
|
762
|
+
ax.set_ylabel(ylabel)
|
|
698
763
|
|
|
699
764
|
if levels is None:
|
|
700
|
-
levels =
|
|
701
|
-
|
|
765
|
+
levels = _colorbar_levels(ax, lo, hi, cmap, zlabel)
|
|
766
|
+
cf = ax.contourf(gx, gy, gz, levels=levels, cmap=cmap)
|
|
767
|
+
cbar = fig.colorbar(cf, cax=_colorbar_axes(ax), label=zlabel)
|
|
702
768
|
if contour_step is None:
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
769
|
+
line_levels = np.asarray(cf.levels)
|
|
770
|
+
else:
|
|
771
|
+
line_levels = np.arange(lo, hi + contour_step, contour_step)
|
|
772
|
+
inside = line_levels[(line_levels > np.nanmin(gz)) & (line_levels < np.nanmax(gz))]
|
|
773
|
+
if len(inside):
|
|
774
|
+
lines = ax.contour(
|
|
775
|
+
gx,
|
|
776
|
+
gy,
|
|
777
|
+
gz,
|
|
778
|
+
levels=inside,
|
|
779
|
+
colors=_contour_line_colors(cf, inside, style),
|
|
780
|
+
linewidths=style.narrow,
|
|
781
|
+
)
|
|
782
|
+
cbar.add_lines(lines)
|
|
715
783
|
|
|
716
|
-
# NEB paths: white line + coral circles + numbered images
|
|
717
784
|
if paths is not None:
|
|
785
|
+
outline = [
|
|
786
|
+
mpe.Stroke(
|
|
787
|
+
linewidth=style.wide + 2 * style.narrow, foreground=style.textcolor
|
|
788
|
+
),
|
|
789
|
+
mpe.Normal(),
|
|
790
|
+
]
|
|
791
|
+
offset = style.gap + style.marker / 2
|
|
718
792
|
for _label, (xs, ys) in paths.items():
|
|
719
793
|
xs = np.asarray(xs)
|
|
720
794
|
ys = np.asarray(ys)
|
|
721
|
-
ax.plot(
|
|
795
|
+
ax.plot(
|
|
796
|
+
xs,
|
|
797
|
+
ys,
|
|
798
|
+
color=style.facecolor,
|
|
799
|
+
linewidth=style.wide,
|
|
800
|
+
path_effects=outline,
|
|
801
|
+
zorder=30,
|
|
802
|
+
)
|
|
722
803
|
ax.scatter(
|
|
723
804
|
xs,
|
|
724
805
|
ys,
|
|
725
|
-
c=RUHI_COLORS["
|
|
726
|
-
s=
|
|
806
|
+
c=RUHI_COLORS["sky"],
|
|
807
|
+
s=style.marker**2,
|
|
727
808
|
marker="o",
|
|
728
|
-
edgecolors=
|
|
729
|
-
linewidths=
|
|
809
|
+
edgecolors=style.facecolor,
|
|
810
|
+
linewidths=style.narrow,
|
|
730
811
|
zorder=31,
|
|
731
812
|
)
|
|
813
|
+
# Image numbers go below the path, point labels above it, so the
|
|
814
|
+
# two never cover each other where an image is a stationary point.
|
|
732
815
|
for j in range(len(xs)):
|
|
733
816
|
ax.annotate(
|
|
734
817
|
str(j + 1),
|
|
735
818
|
(xs[j], ys[j]),
|
|
736
819
|
textcoords="offset points",
|
|
737
|
-
xytext=(
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
820
|
+
xytext=(offset, -offset),
|
|
821
|
+
va="top",
|
|
822
|
+
fontsize=style.footnote,
|
|
823
|
+
color=style.facecolor,
|
|
824
|
+
path_effects=style.halo(),
|
|
741
825
|
zorder=32,
|
|
742
826
|
)
|
|
743
827
|
|
|
744
|
-
# Points: context-dependent markers
|
|
745
828
|
if points is not None:
|
|
746
829
|
_min_labels = iter(["A", "B", "C", "D", "E"])
|
|
747
830
|
_sad_labels = iter(["S1", "S2", "S3", "S4"])
|
|
831
|
+
big = style.marker_large
|
|
832
|
+
offset = style.gap + big / 2
|
|
833
|
+
label_kw = {
|
|
834
|
+
"textcoords": "offset points",
|
|
835
|
+
"xytext": (offset, offset),
|
|
836
|
+
"va": "bottom",
|
|
837
|
+
"fontsize": style.body,
|
|
838
|
+
"fontweight": "bold",
|
|
839
|
+
"color": style.facecolor,
|
|
840
|
+
"path_effects": style.halo(),
|
|
841
|
+
"zorder": 34,
|
|
842
|
+
}
|
|
843
|
+
marker_kw = {
|
|
844
|
+
"c": style.facecolor,
|
|
845
|
+
"s": big**2,
|
|
846
|
+
"edgecolors": style.textcolor,
|
|
847
|
+
"linewidths": style.narrow,
|
|
848
|
+
"zorder": 33,
|
|
849
|
+
}
|
|
748
850
|
|
|
749
851
|
for pname, (xs, ys) in points.items():
|
|
750
852
|
xs = np.asarray(xs)
|
|
751
853
|
ys = np.asarray(ys)
|
|
752
854
|
|
|
753
855
|
if "minim" in pname.lower():
|
|
754
|
-
|
|
755
|
-
ax.scatter(
|
|
756
|
-
xs,
|
|
757
|
-
ys,
|
|
758
|
-
c="white",
|
|
759
|
-
s=80,
|
|
760
|
-
marker="o",
|
|
761
|
-
edgecolors="black",
|
|
762
|
-
linewidths=1.5,
|
|
763
|
-
zorder=33,
|
|
764
|
-
)
|
|
856
|
+
ax.scatter(xs, ys, marker="o", **marker_kw)
|
|
765
857
|
for k in range(len(xs)):
|
|
766
|
-
|
|
767
|
-
ax.annotate(
|
|
768
|
-
lbl,
|
|
769
|
-
(xs[k], ys[k]),
|
|
770
|
-
textcoords="offset points",
|
|
771
|
-
xytext=(6, 6),
|
|
772
|
-
fontsize=12,
|
|
773
|
-
fontweight="bold",
|
|
774
|
-
color="white",
|
|
775
|
-
path_effects=_STROKE,
|
|
776
|
-
zorder=34,
|
|
777
|
-
)
|
|
858
|
+
ax.annotate(next(_min_labels, f"M{k}"), (xs[k], ys[k]), **label_kw)
|
|
778
859
|
elif "saddle" in pname.lower():
|
|
779
|
-
|
|
780
|
-
ax.scatter(
|
|
781
|
-
xs,
|
|
782
|
-
ys,
|
|
783
|
-
c="white",
|
|
784
|
-
s=100,
|
|
785
|
-
marker="X",
|
|
786
|
-
edgecolors="black",
|
|
787
|
-
linewidths=1.5,
|
|
788
|
-
zorder=33,
|
|
789
|
-
)
|
|
860
|
+
ax.scatter(xs, ys, marker="X", **marker_kw)
|
|
790
861
|
for k in range(len(xs)):
|
|
791
|
-
|
|
792
|
-
ax.annotate(
|
|
793
|
-
lbl,
|
|
794
|
-
(xs[k], ys[k]),
|
|
795
|
-
textcoords="offset points",
|
|
796
|
-
xytext=(6, 6),
|
|
797
|
-
fontsize=12,
|
|
798
|
-
fontweight="bold",
|
|
799
|
-
color="white",
|
|
800
|
-
path_effects=_STROKE,
|
|
801
|
-
zorder=34,
|
|
802
|
-
)
|
|
862
|
+
ax.annotate(next(_sad_labels, f"S{k}"), (xs[k], ys[k]), **label_kw)
|
|
803
863
|
else:
|
|
804
|
-
#
|
|
864
|
+
# A star fills half its box, so it gets twice the area.
|
|
805
865
|
ax.scatter(
|
|
806
866
|
xs,
|
|
807
867
|
ys,
|
|
808
|
-
c=RUHI_COLORS["sunshine"],
|
|
809
|
-
s=120,
|
|
810
868
|
marker="*",
|
|
811
|
-
|
|
812
|
-
linewidths=1.0,
|
|
813
|
-
zorder=33,
|
|
869
|
+
**{**marker_kw, "c": RUHI_COLORS["sunshine"], "s": 2 * big**2},
|
|
814
870
|
)
|
|
815
871
|
|
|
816
|
-
|
|
817
|
-
|
|
872
|
+
if height is None:
|
|
873
|
+
fit_height(fig)
|
|
818
874
|
return fig
|
|
819
875
|
|
|
820
876
|
|
|
877
|
+
# Matplotlib's colour-bar defaults (Figure.colorbar): gap to the parent of 0.05
|
|
878
|
+
# of its width, and length 20 times the thickness.
|
|
879
|
+
_CBAR_PAD = 0.05
|
|
880
|
+
_CBAR_ASPECT = 20.0
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
def _colorbar_axes(ax):
|
|
884
|
+
"""Colour-bar axes exactly as tall as the equal-aspect ``ax``.
|
|
885
|
+
|
|
886
|
+
A colour bar attached with ``ax=`` spans the layout cell, which is taller
|
|
887
|
+
than an equal-aspect map; this one is an inset on the map's own box, with
|
|
888
|
+
matplotlib's default gap and aspect. Its width follows from the data
|
|
889
|
+
aspect, which an equal-aspect box keeps, so no layout pass is needed.
|
|
890
|
+
"""
|
|
891
|
+
x0, x1 = ax.get_xlim()
|
|
892
|
+
y0, y1 = ax.get_ylim()
|
|
893
|
+
box_aspect = abs(y1 - y0) / abs(x1 - x0)
|
|
894
|
+
return ax.inset_axes([1.0 + _CBAR_PAD, 0.0, box_aspect / _CBAR_ASPECT, 1.0])
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
def _colorbar_levels(ax, lo, hi, cmap, label) -> np.ndarray:
|
|
898
|
+
"""Levels at the ticks matplotlib's automatic locator puts on the colour
|
|
899
|
+
bar of ``ax`` for ``[lo, hi]``, extended by one tick to cover the range."""
|
|
900
|
+
fig = ax.figure
|
|
901
|
+
probe = fig.colorbar(
|
|
902
|
+
ScalarMappable(Normalize(lo, hi), cmap=cmap), cax=_colorbar_axes(ax), label=label
|
|
903
|
+
)
|
|
904
|
+
fig.draw_without_rendering()
|
|
905
|
+
locator = AutoLocator()
|
|
906
|
+
locator.set_axis(probe.ax.yaxis)
|
|
907
|
+
levels = locator.tick_values(lo, hi)
|
|
908
|
+
probe.remove()
|
|
909
|
+
return levels
|
|
910
|
+
|
|
911
|
+
|
|
912
|
+
def _contour_line_colors(filled, line_levels, style) -> list[str]:
|
|
913
|
+
"""Text or background colour for each line, whichever contrasts more with
|
|
914
|
+
the filled bands on both sides of it."""
|
|
915
|
+
bounds = np.asarray(filled.levels)
|
|
916
|
+
bands = filled.to_rgba(filled.cvalues)[:, :3]
|
|
917
|
+
last = len(bands) - 1
|
|
918
|
+
candidates = (style.textcolor, style.facecolor)
|
|
919
|
+
colors = []
|
|
920
|
+
for value in line_levels:
|
|
921
|
+
below = int(np.clip(np.searchsorted(bounds, value, side="left") - 1, 0, last))
|
|
922
|
+
above = int(np.clip(np.searchsorted(bounds, value, side="right") - 1, 0, last))
|
|
923
|
+
colors.append(best_contrast(bands[[below, above]], candidates))
|
|
924
|
+
return colors
|
|
925
|
+
|
|
926
|
+
|
|
821
927
|
def plot_gp_progression(
|
|
822
928
|
grids: dict[int, dict],
|
|
823
929
|
_true_energy,
|
|
@@ -985,8 +1091,8 @@ def plot_nll_landscape(
|
|
|
985
1091
|
hi = float(np.quantile(log_finite, 0.98))
|
|
986
1092
|
gz_clipped = np.clip(gz_log, 0, hi)
|
|
987
1093
|
|
|
988
|
-
# Reversed
|
|
989
|
-
cf = ax.contourf(gx, gy, gz_clipped, levels=20, cmap="
|
|
1094
|
+
# Reversed sequential map: low NLL is light and warm.
|
|
1095
|
+
cf = ax.contourf(gx, gy, gz_clipped, levels=20, cmap=f"{RUHI_SEQUENTIAL}_r")
|
|
990
1096
|
fig.colorbar(
|
|
991
1097
|
cf,
|
|
992
1098
|
ax=ax,
|