相关疑难解决方法(0)

使用matplotlib为散点图添加X轴下方的标题

我是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()
Run Code Online (Sandbox Code Playgroud)

正如您在图像中看到的,我的标题位于散点图下方,是否有办法将其精确地置于X轴下方?我的散点图看起来也是矩形的,有没有办法让它像方块一样?

在此输入图像描述

plot matplotlib

12
推荐指数
4
解决办法
2万
查看次数

标签 统计

matplotlib ×1

plot ×1