mendeleev
support two interactive plotting backends
Depending on your environment being the classic jupyter notebook or jupyterlab you might have to do additional configuration steps, so if you're not getting expected results see plotly of bokeh documentation.
There are two plotting functions for each of the backends:
periodic_table_plotly
in mendeleev.vis.plotly
periodic_table_bokeh
in mendeleev.vis.bokeh
that you can use to customize the visualizations even further.
Both functions take the same keyword arguments as the periodic_table
function but the also require a DataFrame
with periodic table data. You can get the default data using the create_vis_dataframe
function. Let's start with an example using the plotly
backend.
from mendeleev.vis import create_vis_dataframe, periodic_table_plotly
elements = create_vis_dataframe()
periodic_table_plotly(elements)
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.
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'))}
elements['block_color'] = elements['block'].map(blockcmap)
periodic_table_plotly(elements, colorby='block_color')
You can also create your own properties to be displayed using pandas awesome methods for manipulating data. For example let's consider the difference of electronegativity between every element and the Oxygen atom. To calculate the values we will use Allen scale this time and call our new value ENX-ENO
.
elements.loc[:, 'ENX-ENO'] = elements.loc[elements['symbol'] == 'O', 'en_allen'].values - elements.loc[:, 'en_allen']
periodic_table_plotly(elements, attribute='ENX-ENO', colorby='attribute',
cmap='viridis', title='Allen Electronegativity wrt. Oxygen')
As a second example let's consider a difference between the covalent_radius_slater
and covalent_radius_pyykko
values
elements['cov_rad_diff'] = elements['atomic_radius'] - elements['covalent_radius_pyykko']
periodic_table_plotly(elements, attribute='cov_rad_diff', colorby='attribute',
title='Covalent Radii Difference', cmap='viridis')
We can also use the Bokeh
backed in the same way but we need to take a few extra steps to render the result in a notebook
from bokeh.plotting import show, output_notebook
from mendeleev.vis import periodic_table_bokeh
First we need to enable notebook output
output_notebook()
fig = periodic_table_bokeh(elements)
show(fig)
fig = periodic_table_bokeh(elements, attribute="atomic_radius", colorby="attribute")
show(fig)