Kamis, 14 Maret 2019

Adding labels to points in seaborn stripplot

I'm using stripplot on seaborn to show energies of d orbitals in a series of metallic centers.

Here is the dataframe:


dxy dyz dz2 dxz dx2-y2
Fe -0.25336 -0.24661 -0.22991 -0.07644 -0.16229
Co -0.38294 -0.38050 -0.34952 -0.21271 -0.27173
Ni -0.47550 -0.47504 -0.46817 -0.44385 -0.45632

And using this code I'm quite close to what I want (resulting image below):


plt.figure(figsize=(3, 7))
sns.stripplot(x=df.index, y="dxy", data=df, jitter=False, dodge=True, size=44, marker="_", linewidth=2)
sns.stripplot(x=df.index, y="dyz", data=df, jitter=False, dodge=True, size=44, marker="_", linewidth=2)
sns.stripplot(x=df.index, y="dz2", data=df, jitter=False, dodge=True, size=44, marker="_", linewidth=2)
sns.stripplot(x=df.index, y="dxz", data=df, jitter=False, dodge=True, size=44, marker="_", linewidth=2)
sns.stripplot(x=df.index, y="dx2-y2", data=df, jitter=False, dodge=True, size=44, marker="_", linewidth=2)
plt.ylabel("Energy (Eh)")
plt.savefig('svm_conf.png', dpi=400)

I'd like to add the name of each orbital (dxy, dxz etc), as a label, to the right (or the best possible position) on each point (or line in this case haha).

Any help is much appreciated.

P.S.: I can see that the figure generated at the end is missing part of the numbers in the Y axis. Why?

Update

I'm giving a try to a seaborn version of the solution proposed by @ImportanceOfBeingErnest. Testing with only one of the markers, for now, I'm getting this AttributeError: 'NoneType' object has no attribute 'update' with a long traceback that doesn't make much sense to me. Here is my code:


dxy = sns.stripplot(x=df.index, y="dxy", data=df, jitter=False, dodge=True, size=44, marker="_", linewidth=2)
for line in range(0, df.shape[0]):
dxy.text(df.index[line], df.dxy[line], "teste", horizontalalignment='right', size='medium', color='black')

enter image description here



from Adding labels to points in seaborn stripplot

Adding labels to points in seaborn stripplot Rating: 4.5 Diposkan Oleh: Admin

0 komentar:

Posting Komentar

Popular Posts