Skip to content

Commit 6de65da

Browse files
JoshuaNgXYpre-commit-ci[bot]tschaume
authored
Update pourbaix heatmap plots (#398)
* Update pourbaix.py Removing x, y, and z labels on hovertext of heatmaps * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update pourbaix.py Small color update to ion/default color Removed extra box from hovertext of heatmap off Pourbaix plots. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update Colors pourbaix.py Updated some whites to be a bit further offwhite so that it contrasts with the white background. Updated the heatmap color scheme to include the full range but use an exponentially scaled color scheme based off magma. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Patrick Huck <phuck@lbl.gov>
1 parent 1d58114 commit 6de65da

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

crystal_toolkit/components/pourbaix.py

+27-14
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class PourbaixDiagramComponent(MPComponent):
119119
# Deprecated. This method returns a figure with Pourbaix domains as "shapes" and labels
120120
# as "annotations." The new figure method instead returns a Pourbaix diagram with
121121
# domains and labels as independent traces, so that they can be interacted with and
122-
# placed ona legend.
122+
# placed on a legend.
123123
#
124124
# Static method for getting plotly figure from a Pourbaix diagram.
125125
#
@@ -334,7 +334,7 @@ def get_figure(
334334

335335
if not heatmap_entry:
336336
if legend_entry == "Ion" or legend_entry == "Unknown":
337-
fillcolor = "rgb(255,255,250,1)" # same color as old website
337+
fillcolor = "rgb(255,245,255,1)" # New purple white color
338338
elif legend_entry == "Mixed Ion":
339339
fillcolor = "rgb(255,255,240,1)"
340340
elif legend_entry == "Solid":
@@ -356,6 +356,7 @@ def get_figure(
356356
# legendgrouptitle={"text": legend_entry},
357357
name=legend_entry,
358358
text=f"{clean_formula} ({entry.entry_id})",
359+
hoverinfo="text",
359360
marker={"color": "Black"},
360361
line={"color": "Black", "width": 0},
361362
mode="lines",
@@ -376,9 +377,9 @@ def get_figure(
376377
path += "Z"
377378

378379
# stable entries are black with default color scheme,
379-
# so use white lines instead
380+
# so use off-white lines instead
380381
line = (
381-
{"color": "White", "width": 4}
382+
{"color": "rgba(255,235,255,1)", "width": 4}
382383
if heatmap_entry
383384
else {"color": "Black", "width": 1}
384385
)
@@ -454,7 +455,7 @@ def get_text_size(available_vertical_space):
454455
)
455456

456457
# Generate hoverinfo
457-
hovertexts = []
458+
hoverlabel = []
458459
for ph_val, v_val, de_val in zip(
459460
ph_mesh.ravel(), v_mesh.ravel(), decomposition_e.ravel()
460461
):
@@ -464,13 +465,13 @@ def get_text_size(available_vertical_space):
464465
f"V={v_val:.2f}",
465466
]
466467
hovertext = "<br>".join(hovertext)
467-
hovertexts.append(hovertext)
468-
hovertexts = np.reshape(hovertexts, list(decomposition_e.shape))
468+
hoverlabel.append(hovertext)
469+
hoverlabel = np.reshape(hoverlabel, list(decomposition_e.shape))
469470

470471
# Enforce decomposition limit energy
471-
decomposition_e = np.min(
472-
[decomposition_e, np.ones(decomposition_e.shape)], axis=0
473-
)
472+
# decomposition_e = np.min(
473+
# [decomposition_e, np.ones(decomposition_e.shape)], axis=0
474+
# )
474475

475476
heatmap_formula = unicodeify(
476477
Composition(heatmap_entry.composition).reduced_formula
@@ -484,14 +485,26 @@ def get_text_size(available_vertical_space):
484485
"title": "∆G<sub>pbx</sub> (eV/atom)",
485486
"titleside": "right",
486487
},
487-
colorscale=PourbaixDiagramComponent.colorscale, # or magma
488-
zmin=0,
489-
zmax=1,
488+
colorscale=[
489+
[0, "#000004"],
490+
[0.031, "#180f3d"],
491+
[0.044, "#440f76"],
492+
[0.063, "#721f81"],
493+
[0.088, "#9e2f7f"],
494+
[0.125, "#cd4071"],
495+
[0.177, "#f1605d"],
496+
[0.25, "#fd9668"],
497+
[0.354, "#feca8d"],
498+
[0.5, "#fcfdbf"],
499+
[1, "#fcfdbf"],
500+
], # Custom Magma built exponentially rather than linearly
501+
ncontours=50,
490502
connectgaps=True,
491503
line_smoothing=0,
492504
line_width=0,
493505
# contours_coloring="heatmap",
494-
text=hovertexts,
506+
text=hoverlabel,
507+
hoverinfo="text",
495508
name=f"{heatmap_formula} ({heatmap_entry.entry_id}) Heatmap",
496509
showlegend=True,
497510
)

0 commit comments

Comments
 (0)