【发布时间】:2015-11-30 23:52:38
【问题描述】:
我对 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 轴下方?另外我的散点图看起来是矩形的,有没有办法让它像方形?
【问题讨论】:
标签: matplotlib plot