我对Python和Matplotlib库都比较陌生。我已经使用Matplotlib创建了一个散点图,现在希望在X轴下方添加标题。以下是我的代码:
from matplotlib import pyplot as plt
import numpy as np
from pylab import *
file = open('distribution.txt', 'r')
txt="I need the caption to be present a little below X-axis"
x=[]
y=[]
for line in file:
new=line.rstrip()
mystring=new.split("\t")
x.append(mystring[0])
y.append(mystring[1])
fig = plt.figure()
ax1 = fig.add_axes((0.1,0.4,0.8,0.5))
ax1.set_title("This is my title")
ax1.set_xlabel('X-axis')
ax1.set_ylabel('Y-axis')
ax1.scatter(x,y, c='r')
fig.text(.05,.05,txt)
plt.xlim(0, 1.05)
plt.ylim(0, 2.5)
plt.show()
如您在图片中所见,我的标题远低于散点图,是否有办法将其准确地放在X轴下方?另外,我的散点图看起来是矩形的,有没有办法使其变成正方形?