Visualization module

Periodic table visualizations

The main entry point for visualizing periodic tables with different properties is the periodictable.periodic_table() function.

periodic_table(attribute: str = 'atomic_weight', height: int = 800, width: int = 1200, decimals: int = 3, colorby: str = 'color', missing: str = '#ffffff', title: str = 'Periodic Table', cmap: str = 'RdBu_r', wide_layout: bool = False, include_f_block: bool = True, backend='plotly')[source]

High level api for visualizing periodic tables.

Currently supports plotting backends:
  • bokeh

  • plotly

Parameters:
  • attribute (str, optional) – Name of the attribute to display. Defaults to “atomic_weight”.

  • height (int, optional) – Height of the figure in pixels. Defaults to 800.

  • width (int, optional) – Width of the figure in pixels. Defaults to 1200.

  • decimals (int, optional) – Number of decimals to be displayed for attribute. Defaults to 3.

  • colorby (str, optional) – Name of the columns that contains color values. Defaults to “color”.

  • missing (str, optional) – Hex code for the color to be used for missing values. Defaults to “#ffffff”.

  • title (str, optional) – Title. Defaults to “Periodic Table”.

  • cmap (str, optional) – Colormap name. Defaults to “RdBu_r”.

  • wide_layout (bool, optional) – If True wide layout is used with f block between s and d blocks. Defaults to False.

  • include_f_block (bool, optional) – Flag indicating whether to include the _f_ block. Defaults to True.

  • backend (str, optional) – Plotting backennd. Defaults to “plotly”.

Raises:

ValueError – upon specifying unsupported ploting backend.

Returns:

figure instance, either plotly.Figure or bokeh.plotting.figure

Return type:

fig

bokeh

periodic_table_bokeh(elements: pandas.DataFrame, attribute: str = 'atomic_weight', cmap: str = 'RdBu_r', colorby: str = 'color', decimals: int = 3, height: int = 800, missing: str = '#ffffff', title: str = 'Periodic Table', wide_layout: bool = False, width: int = 1200)[source]

Use Bokeh backend to plot the periodic table.

Parameters:
  • elements – Pandas DataFrame with the elements data. Needs to have x and y columns with coordianates for each tile.

  • attribute – Name of the attribute to be displayed

  • cmap – Colormap to use, see matplotlib colormaps

  • colorby – Name of the column containig the colors

  • decimals – Number of decimals to be displayed in the bottom row of each cell

  • height – Height of the figure in pixels

  • missing – Hex code of the color to be used for the missing values

  • title – Title to appear above the periodic table

  • wide_layout – wide layout variant of the periodic table

  • width – Width of the figure in pixels

plotly

create_annotation(row: pandas.Series, attr: str, size: int = 10, x_offset: float = 0.0, y_offset: float = 0.0) Annotation[source]

Create an annotation from pandas series

create_tile(element: pandas.Series, color: str, x_offset: float = 0.45, y_offset: float = 0.45) Shape[source]

Create tile shape

periodic_table_plotly(elements: pandas.DataFrame, attribute: str = 'atomic_weight', cmap: str = 'RdBu_r', colorby: str = 'color', decimals: int = 3, height: int = 800, missing: str = '#ffffff', title: str = 'Periodic Table', wide_layout: bool = False, width: int = 1200) Figure[source]

Create a periodic table visualization with plotly.Figure

Parameters:
  • elements – Pandas DataFrame with the elements data. Needs to have x and y columns with coordianates for each tile.

  • attribute – Name of the attribute to be displayed

  • cmap – Colormap to use, see matplotlib colormaps

  • colorby – Name of the column containig the colors

  • decimals – Number of decimals to be displayed in the bottom row of each cell

  • height – Height of the figure in pixels

  • missing – Hex code of the color to be used for the missing values

  • title – Title to appear above the periodic table

  • wide_layout – wide layout variant of the periodic table

  • width – Width of the figure in pixels

seaborn

heatmap(elements: pandas.DataFrame, prop: str, style: str = 'whitegrid', figsize: Tuple[int] = (16, 10), cmap: str = 'RdBu_r', lw: int = 1, output: str = None, **kwargs)[source]

Plot a heatmap of the given property

Parameters:
  • elements – DataFrame with data about elements

  • prop – Name of the attribute of Element object that is available from the elements table

  • style – Seaborn style option, default=’whitegrid

  • figsize – Size of the plot, default=(16, 10)

  • cmap – Colormap to use, default=’RdBu_r’

  • lw – Seaborn heatmap linewidths argumentm default=1, see http://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.heatmap.html

  • output – File name to save the plot, by default nothing is saved

utils

add_tile_coordinates(df: pandas.DataFrame, x_coord: str = 'group_id', y_coord: str = 'period', include_f_block: bool = True, wide_layout: bool = False) pandas.DataFrame[source]

Calculate coordinates for the tile centers

Parameters:
  • df – dataframe

  • x_coord – attribute to use as x coordinate

  • y_coord – attribute to use as y coordinate

  • wide_layout – Show the long version of the periodic table with the f block between the s and d blocks

  • include_f_block – Show the elements from the f block

colormap_column(elements: pandas.DataFrame, column: str, cmap: str = 'RdBu_r', missing: str = '#ffffff')[source]

Return a new DataFrame with the same size (and index) as elements with a column cmap containing HEX color mapping from cmap colormap.

Parameters:
  • elements – DataFrame with the data

  • column – Name of the column to be color mapped

  • cmap – Name of the colormap, see matplotlib.org

  • missing – HEX color for the missing values (NaN or None)

create_vis_dataframe(x_coord: str = 'group_id', y_coord: str = 'period', include_f_block: bool = True, wide_layout: bool = False)[source]

Base DataFrame for visualizations

Parameters:
  • x_coord – attribute to use as x coordinate

  • y_coord – attribute to use as y coordinate

  • include_f_block – show the elements from the f block

  • wide_layout – show the long version of the periodic table with the f block between the s and d blocks