在python图中以大字体打印变量

在python图中以大字体打印变量,python,matplotlib,plot,Python,Matplotlib,Plot,我从另一个来源借用了一些代码,我想编辑生成的图形。下面是脚本中的相关代码 import gtk #the gui toolkit we'll use: from matplotlib.figure import Figure from Tkinter import * from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas #create a window to put the plot

我从另一个来源借用了一些代码,我想编辑生成的图形。下面是脚本中的相关代码

import gtk #the gui toolkit we'll use:
from matplotlib.figure import Figure
from Tkinter import *
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas

#create a window to put the plot in
win = gtk.Window()
#connect the destroy signal (clicking the x in the corner)
win.connect("destroy", quit_app)
win.set_default_size(600,500)

#create a plot:
fig = Figure()
ax = fig.add_subplot(111,xlabel='Time Step', ylabel='Temp (deg C)', axisbg='black')
ax.set_ylim(0,100) # set limits of y axis.

canvas = FigureCanvas(fig) #put the plot onto a canvas
win.add(canvas) #put the canvas in the window

#show the window
win.show_all()
win.set_title("ready to receive data");
line, = ax.plot(times,yvals, color='red')

while(1):
  line.set_ydata(yvals) # draw the line
  fig.canvas.draw() # update the Canvas
  win.set_title("Temp: "+str(yvals[49])+" deg C")
我不知道上面所有的代码是否都是必需的,但这就是我能找到的所有与“绘图”相关的代码

因此,无论如何,代码在我的程序中工作得非常完美

我想创建两个任务: 1我想包括当前显示在窗口标题中的“stryvals[49]”变量,该变量将以大字体显示在绘图下方。因此,我认为我需要使窗口的大小大一点,以配合文本,但不知道如何打印它

2我设法将绘图本身的背景更改为黑色,以绘制红线。但是我如何才能将窗口本身的背景更改为全黑色,并将x/y轴也更改为红色呢


谢谢

1您最可能要查找的是matplotlib text命令。看一看使用文本的部分。创建两个单独的轴可能会很方便,这样您就可以真正将文本放在整个图形的下方。也许将文本放在xlabel位置就足够了

import matplotlib.pyplot as plt
plt.xlabel('yourtext')
2.已经有一些很好的答案可能会对你有所帮助。 至于轴的颜色


如果您想保存图形,也可以查看一下。

我没有使用pyplot-在任何时候我都不会导入它-因此代码不会工作。要更改x轴以显示不断更新的变量,我需要将其放入while循环中。我想我需要以某种方式修改这一行:ax=fig.add_subplot111,xlabel='Time Step',ylabel='Temp deg C',axisbg='black',不过,您需要导入图形。稍后创建ax。所以应该有ax.text,但不显式导入pyplot,就不会有ax.xlabel。