Xtics标签未完整显示

问题描述 投票:0回答:1

如何使用xticks标签解决此问题?

plt.tight_layout()

无济于事。

代码:

import matplotlib.pyplot as plt
import numpy as np
import re

x = ('5L8 9O7 4H 7F')
print(type(x))
xaxes = x.split()
y = [4.7, 5.7, 4, 6.4]
print(xaxes)
print(y)

plt.rcParams["figure.figsize"] = [11,15]

splitted_xaxes = [re.search('^([0-9]*)([^0-9]*)([0-9]*)$', label).groups() for label in xaxes ]
xaxes = [r'${}^{'+splitted[0]+r'}_{}'+splitted[1]+r'^{'+splitted[2] + '}_{}$' for splitted in splitted_xaxes]

plt.scatter(xaxes,y)

plt.xlabel(r'$\it{L}$', fontsize=20, labelpad=30) #labelpad - vzdálenost od osy
plt.ylabel(r'$\it{LK}$ (eV)', fontsize=20)
plt.title('Img', fontsize=28, fontweight='bold')
plt.yticks(fontsize=18)
plt.xticks(fontsize=18)

plt.tight_layout()
plt.savefig('img.png', dpi=199) 
plt.show()
python-3.x matplotlib axis-labels
1个回答
0
投票

您的字符串中有一个额外的_{}。即

'${}^{8}S_{}$'

enter image description here

但是

'${}^{8}S$'

enter image description here


基本问题是this

© www.soinside.com 2019 - 2024. All rights reserved.