Visualizing custom periodic tables

In this tutorial you’ll how to use mendeleev to create customized visualizations of the periodic table.

The most convenient method to use for this is periodic_table function from mendeleev.vis module.

[1]:
from mendeleev.vis import periodic_table

Make sure you you have optional vis dependencies installed when installing mendeleev. If you are using pip install with

pip install mendeleev[vis]

To see the default visualization of the periodic table simply call the imported function

[2]:
periodic_table()
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning: DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.
  .apply(lambda x: x["atomic_number"] - x["atomic_number"].min())

Data type cannot be displayed: application/vnd.plotly.v1+json

mendeleev stores also two color schemes for atoms that are frequently used for visualizing molecular structures. One set is stored in the cpk_color column and refers to CPK coloring, another is stored in jmol_color column and is used by the Jmol program, finally there is also coloring scheme from MOLCAS GV program store in the molcas_gv_color attribute. They can be displayed either by hovering of the element to display a tooltip or used directly to color the element cells.

[3]:
periodic_table(colorby="jmol_color", title="JMol Colors")
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

[4]:
periodic_table(colorby="cpk_color", title="CPK Colors")
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

[5]:
periodic_table(colorby="molcas_gv_color", title="MOLCAS GV Colors")
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

Visualizing properties

Any of the properties in mendeleev can now be visualized and color coded. This means that the value of selected attribute will be visible on each element and also it is possible to use the attribute to color code the background of each element.

Let’s first use the covalent_radius_pyykko and display the values with the default color coding by series

[6]:
periodic_table(attribute="covalent_radius_pyykko", title="Covalent Radii of Pyykko")
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

Now let’s use the same attribute but in addition color code by the actual values, by adding colorby='attribute' argument

[7]:
periodic_table(
    attribute="covalent_radius_pyykko",
    colorby="attribute",
    title="Covalent Radii of Pyykko",
)
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

The color map can aslo be csutomized using the cmap argument to any of the standard colormaps available in matplotlib

[8]:
periodic_table(
    attribute="covalent_radius_pyykko",
    colorby="attribute",
    cmap="spring",
    title="Covalent Radii of Pyykko",
)
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

Let also see one of the more modern colormaps: viridis, plasma, inferno and magma.

[9]:
periodic_table(
    attribute="covalent_radius_pyykko",
    colorby="attribute",
    cmap="inferno",
    title="Covalent Radii of Pyykko",
)
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

Let’s try a different property: density

[10]:
periodic_table(attribute="density", colorby="attribute", title="Atomic Volume")
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

[11]:
periodic_table(
    attribute="en_pauling",
    colorby="attribute",
    title="Pauling's Electronegativity",
    cmap="viridis",
)
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json

Wide 32-column version

The periodic_table function can also present the periodic table in the so-called wide format with the f-block between the s- and d-blocks resulting in 32 columns.

[12]:
periodic_table(height=600, width=1500, wide_layout=True)
/home/docs/checkouts/readthedocs.org/user_builds/mendeleev/envs/latest/lib/python3.11/site-packages/mendeleev/vis/utils.py:43: FutureWarning:

DataFrameGroupBy.apply operated on the grouping columns. This behavior is deprecated, and in a future version of pandas the grouping columns will be excluded from the operation. Either pass `include_groups=False` to exclude the groupings or explicitly select the grouping columns after groupby to silence this warning.

Data type cannot be displayed: application/vnd.plotly.v1+json