python将横坐标轴的值倾斜一定角度,以避免重叠
import matplotlib.pyplot as plt
"""
a1 = "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.17979811 0.0 0.19455098 0.22128937 0.20096813 0.20339341 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0"
aa1 = "the so-called grandmother hypothesis based on studies of african hunter-gatherer groups suggests that infertile women are vital for successful child-rearing despite being unable to produce children themselves "
a2 = "0.0 0.0 0.0 0.0 0.0 0.18585661 0.0 0.0 0.19287187 0.21022634 0.20847885 0.20256634 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0"
aa2 = "the grandmother hypothesis suggests that infertile women are very important for raising children"
a1 = "0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.19144899 0.22170746 0.20416436 0.19487111 0.18780807 0.0"
aa1 = "trade between china and india is expected to touch $20 bn this year and chinese investors are now rushing into india - lured by the country s growing wealth"
a2 = "0.0 0.0 0.0 0.0 0.0 0.0 0.19154933 0.0 0.21717739 0.20123896 0.19672251 0.19331184 0.0 0.0"
aa2 = "there is a profitable trade between china and india"
"""
a1 = "0.18417412 0.20065087 0.21265925 0.23537883 0.1671369 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0"
aa1 = "successful plaintiffs recovered punitive damages in texas discrimination cases 53 of the time"
a2 = "0.21300969 0.21517463 0.0 0.18324433 0.20611063 0.0 0.0 0.0 0.0 0.18246076 0.0"
aa2 = "legal costs to recover punitive damages are a deductible business expense "
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
y1 = [float(r) for r in a1.split()]
x1 = [str(i)+"_"+v for i,v in enumerate(aa1.split())]
while len(x1)<len(y1):
x1.append(str(len(x1))+"_.")
for tick in ax1.get_xticklabels(): # 将横坐标倾斜30度,纵坐标可用相同方法
tick.set_rotation(30)
ax1.plot(x1, y1, 'go--')
y2 = [float(r) for r in a2.split()]
x2 = [str(i)+"_"+v for i,v in enumerate(aa2.split())]
while len(x2)<len(y2):
x2.append(str(len(x2))+"_.")
ax2.plot(x2, y2, 'ro--')
for tick in ax2.get_xticklabels():
tick.set_rotation(30)
plt.show()
效果图如下: