-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathptable_hists_plotly.py
More file actions
41 lines (33 loc) · 1.06 KB
/
ptable_hists_plotly.py
File metadata and controls
41 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Periodic table histogram plotly examples."""
# %%
import numpy as np
from pymatgen.core.periodic_table import Element
import pymatviz as pmv
np_rng = np.random.default_rng(seed=0)
data_dict = {
elem.symbol: np_rng.standard_normal(100) + np_rng.standard_normal(100)
for elem in Element
}
# %% Example 1: Basic histogram with colorbar
fig = pmv.ptable_hists_plotly(
data_dict,
bins=30,
colorbar=dict(title="Element Distributions"),
)
fig.show()
# pmv.io.save_and_compress_svg(fig, "ptable-hists-plotly")
# %% Example 2: horizontal colorbar and custom annotations
fig = pmv.ptable_hists_plotly(
data_dict,
bins=30,
colorbar=dict(title="Element Distributions", orientation="h"),
color_elem_strategy="background",
# symbol_kwargs=dict(x=0.25, y=0.8),
# add atomic numbers to top right of each element tile
annotations={
elem.symbol: dict(text=str(idx + 1), font_color="white", y=0.95)
for idx, elem in enumerate(Element)
},
)
fig.show()
# pmv.io.save_and_compress_svg(fig, "ptable-hists-plotly-with-annotations")