Skip to content

Commit 819f688

Browse files
authored
Support passing sequence of structures to plot_structure_2d() to be plotted in grid (#156)
* bump pre-commit hooks * support passing sequence of structures to plot_structure_2d to be plotted in grid supports list, tuple, dict, pd.Series uses keys, structure.properties['id'] or structure.formula as subplot titles in that order * add test_plot_structure_2d_multiple * update all multi-structure call sites of plot_structure_2d()
1 parent aaa7aa1 commit 819f688

File tree

7 files changed

+388
-336
lines changed

7 files changed

+388
-336
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ default_install_hook_types: [pre-commit, commit-msg]
88

99
repos:
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.4.5
11+
rev: v0.4.7
1212
hooks:
1313
- id: ruff
1414
args: [--fix]
@@ -73,7 +73,7 @@ repos:
7373
exclude: ^(site/src/figs/.+\.svelte|data/wbm/20.+\..+|site/src/(routes|figs).+\.(yaml|json)|changelog.md)$
7474

7575
- repo: https://github.com/pre-commit/mirrors-eslint
76-
rev: v9.3.0
76+
rev: v9.4.0
7777
hooks:
7878
- id: eslint
7979
types: [file]
@@ -87,6 +87,6 @@ repos:
8787
- typescript-eslint
8888

8989
- repo: https://github.com/RobertCraigie/pyright-python
90-
rev: v1.1.364
90+
rev: v1.1.365
9191
hooks:
9292
- id: pyright

examples/dataset_exploration/matbench/perovskites/explore_perovskites.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@
4040

4141

4242
# %%
43-
n_rows, n_cols = 3, 4
44-
fig, axs = plt.subplots(n_rows, n_cols, figsize=(3 * n_cols, 3 * n_rows))
45-
46-
for struct, ax in zip(df_perov[Key.structure], axs.flat):
47-
plot_structure_2d(struct, ax=ax)
48-
ax.set_title(struct.formula, fontsize=14)
49-
43+
plot_structure_2d(df_perov[Key.structure].iloc[:12])
5044
plt.savefig("perovskite-structures-2d.pdf")
5145

5246

examples/make_assets/structure_viz.py

+10-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# %%
2+
from typing import cast
3+
24
import matplotlib.pyplot as plt
35
from matminer.datasets import load_dataset
46
from mp_api.client import MPRester
@@ -16,25 +18,14 @@
1618

1719

1820
# %% Plot Matbench phonon structures
19-
n_rows, n_cols = 3, 4
20-
fig, axs = plt.subplots(n_rows, n_cols, figsize=(3 * n_cols, 3 * n_rows))
21-
title = f"{len(axs.flat)} Matbench phonon structures"
21+
n_structs = 12
22+
fig, axs = plot_structure_2d(
23+
df_phonons[Key.structure].iloc[:n_structs],
24+
show_bonds=True,
25+
bond_kwargs=dict(facecolor="gray", linewidth=2, linestyle="dotted"),
26+
)
27+
title = f"{n_structs} Matbench phonon structures"
2228
fig.suptitle(title, fontweight="bold", fontsize=20)
23-
24-
for idx, (row, ax) in enumerate(zip(df_phonons.itertuples(), axs.flat), start=1):
25-
struct = row[Key.structure]
26-
spg_num = struct.get_space_group_info()[1]
27-
struct.add_oxidation_state_by_guess()
28-
29-
plot_structure_2d(
30-
struct,
31-
ax=ax,
32-
show_bonds=True,
33-
bond_kwargs=dict(facecolor="gray", linewidth=2, linestyle="dotted"),
34-
)
35-
sub_title = f"{idx + 1}. {struct.formula} ({spg_num})"
36-
ax.set_title(sub_title, fontweight="bold")
37-
3829
fig.show()
3930
save_and_compress_svg(fig, "matbench-phonons-structures-2d")
4031

@@ -52,7 +43,7 @@
5243
elif "Zr" in site.species:
5344
site.species = {"Zr": 0.5, "Hf": 0.5}
5445

55-
ax = plot_structure_2d(struct)
46+
ax = cast(plt.Axes, plot_structure_2d(struct))
5647
_, spacegroup = struct.get_space_group_info()
5748

5849
formula = struct.formula.replace(" ", "")

examples/matbench_perovskites_eda.ipynb

+8-25
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)