我从其他来源借用了一些代码,我想编辑生成的数字。这是脚本中的相关(我认为)代码。
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)我想要的是包括当前显示在窗口标题中的'str(yvals [49])'变量,以在图下方以大字体显示。所以我认为我需要使窗口大小更大,以配合文本,但不知道如何打印它。
(2)我设法将剧情本身的背景改为黑色,绘制一条红线。但是如何将窗口本身的背景更改为全黑色,将x / y轴更改为红色。
谢谢!
答案 0 :(得分:0)
(1)你最有可能找到matplotlib text命令。查看使用文字的http://matplotlib.org/users/pyplot_tutorial.html部分。创建两个单独的轴可能很方便,因此您可以将文本真正放在整个图形下方。也许将文本放在xlabel位置就足够了?
import matplotlib.pyplot as plt
plt.xlabel('yourtext')
(2)已经有很好的答案可以帮到你:例如How to change the pylab window background color? 至于轴Changing the color of the axis, ticks and labels for a plot in matplotlib
的颜色如果您想保存图片,请查看Matplotlib figure facecolor (background color)。