Plotting tutorial

The plotting module is based on the Bokeh package and enables visualization of various properties of elements. The plotting in the form of periodic table is done by the periodic_plot function that takes a pandas DataFrame.

To embed the plots in the jupyter notebook first the BokehJS needs to be started.

[1]:
from bokeh.plotting import output_notebook, output_file
[2]:
output_notebook()
Loading BokehJS ...

Now we can get the data from mendeleev as a pandas DataFrame through get_table method

[3]:
from mendeleev import get_table
from mendeleev.plotting import periodic_plot
[4]:
ptable = get_table('elements')

To plot the default table pass the ptable to the periodic_plot function

[5]:
periodic_plot(ptable)

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.

[6]:
periodic_plot(ptable, colorby='jmol_color', title="JMol Colors", decimals=3)
[7]:
periodic_plot(ptable, colorby='cpk_color', title='CPK Colors')
[8]:
periodic_plot(ptable, colorby='molcas_gv_color', title='MOLCAS GV Colors')

You can also add a custom color map by assigning color to all the elments. This can be done by creating a custom column in the DataFrame and then using colorby argument to specify which column contains colors. Let’s try to color the elements according to the block they belong to.

[9]:
import seaborn as sns
from matplotlib import colors
blockcmap = {b : colors.rgb2hex(c) for b, c in zip(['s', 'p', 'd', 'f'], sns.color_palette('deep'))}
ptable['block_color'] = ptable['block'].map(blockcmap)
periodic_plot(ptable, colorby='block_color')

Visualizing properties

Any of the properties in ptable can now be visualized. As a first example lets see the covalent_radius_pyykko with the detault colormap, which is RdBu_r

[10]:
periodic_plot(ptable, attribute='covalent_radius_pyykko', colorby='attribute', title="Covalent Radii of Pyykko")