Plotting d orbital diagrams using matplotlib (or s

2019-08-27 07:01发布

guys, I'm a chemist and I've finished an experiment that gave me the energies of a metal d orbitals.

It is relatively easy to get the correct proportion of energies in Excel 1 and use a drawing program like Inkscape to draw the diagram for molecular orbitals (like I did with this one below 2) but I’d love to use python to get a beautiful diagram that considers the energies of my orbitals like we see in the books.

My first attempt using seaborn and swarmplot is obviously too far from the correct approach and maybe (probably!) is not the correct way to get there. I'd be more than happy to achieve something like the right side here in 3.

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

Energies = [-0.40008, -0.39583, -0.38466, -0.23478, -0.21239]
orbitals = ["dz2", "dxy", "dyz", "dx2y2", "dxz"]
df = pd.DataFrame(Energies)
df["Orbitals"] = pd.DataFrame(orbitals)
sns.swarmplot(y=df[0], size=16)

Thanks for any help.

1 The excel one

enter image description here

2 Drawn by hand using the excel version as the model

enter image description here

3 Extracted from literature

enter image description here

1条回答
可以哭但决不认输i
2楼-- · 2019-08-27 07:49

You can draw anything you like deriving from basic shapes and functions in matplotlib. Energy levels could be simple markers, the texts can be produced by annotate.

import numpy as np
import matplotlib.pyplot as plt


Energies = [-0.40008, -0.39583, -0.38466, -0.23478, -0.21239]
orbitals = ["$d_{z^2}$", "$d_{xy}$", "$d_{yz}$", "$d_{x^2 - y^2}$", "$d_{xz}$"]
x = np.arange(len(Energies))

fig, ax = plt.subplots()
ax.scatter(x, Energies, s=1444, marker="_", linewidth=3, zorder=3)
ax.grid(axis='y')

for xi,yi,tx in zip(x,Energies,orbitals):
    ax.annotate(tx, xy=(xi,yi), xytext=(0,-4), size=18,
                ha="center", va="top", textcoords="offset points")

ax.margins(0.2)
plt.show()

enter image description here

查看更多
登录 后发表回答