| 1 |
# This program is public domain |
| 2 |
# Author: Paul Kienzle |
| 3 |
""" |
| 4 |
Table plotter |
| 5 |
""" |
| 6 |
|
| 7 |
__all__ = ['table_plot'] |
| 8 |
|
| 9 |
def table_plot(data, form="line", label=None, title=None): |
| 10 |
""" |
| 11 |
Plot periodic table data using element symbol vs. value. |
| 12 |
|
| 13 |
:Parameters: |
| 14 |
*data* : { Element: float } |
| 15 |
Data values to plot |
| 16 |
|
| 17 |
*form* = "line" : "line|grid" |
| 18 |
Table layout to use |
| 19 |
|
| 20 |
:Returns: None |
| 21 |
""" |
| 22 |
import matplotlib.pyplot as plt |
| 23 |
|
| 24 |
if form == "line": |
| 25 |
bbox = dict(boxstyle="round", lw=1, ec=(0, 0, 0), fc=(0.85, 0.8, 0.8)) |
| 26 |
for el, value in data.items(): |
| 27 |
if value is not None: |
| 28 |
plt.text(el.number, value, el.symbol, |
| 29 |
bbox=bbox, va='center', ha='center') |
| 30 |
plt.xlim(0, 100) |
| 31 |
plt.xlabel('Element number') |
| 32 |
values = [v for v in data.values()] |
| 33 |
minv, maxv = min(values), max(values) |
| 34 |
margin = (maxv - minv)*0.05 |
| 35 |
plt.ylim(minv-margin, maxv+margin) |
| 36 |
if label is not None: |
| 37 |
plt.ylabel(label) |
| 38 |
if title is not None: |
| 39 |
plt.title(title) |