我试图用来matplotlib.ArtistAnimation动画两个子图.我希望随着动画的进行,x轴的值增加,这样动画的总长度就是100,但是在任何时候,子图只向我显示0-24的时间值,然后迭代到100.
这里给出了一个很好的例子.该链接使用FuncAnimation并plot().axes.set_xlim()递增x值以滚动方式使用和更新x轴标签.该代码可通过所提供链接中YouTube视频下方的链接获取.
我在下面附加了代码,显示了我尝试复制这些结果但x限制似乎采用了它们的最终值而不是随时间递增.我还尝试通过仅绘制将在子图中看到的窗口中的值来递增解(而不是轴),但不会增加x轴值.我也试图实现自动缩放,但x轴仍然没有更新.
我也发现这个问题实际上是同一个问题,但问题从来没有得到解答.
这是我的代码:
import matplotlib.pylab as plt
import matplotlib.animation as anim
import numpy as np
#create image with format (time,x,y)
image = np.random.rand(100,10,10)
#setup figure
fig = plt.figure()
ax1=fig.add_subplot(1,2,1)
ax2=fig.add_subplot(1,2,2)
#set up viewing window (in this case the 25 most recent values)
repeat_length = (np.shape(image)[0]+1)/4
ax2.set_xlim([0,repeat_length])
#ax2.autoscale_view()
ax2.set_ylim([np.amin(image[:,5,5]),np.amax(image[:,5,5])])
#set up list of images for animation
ims=[]
for time in xrange(np.shape(image)[0]):
im = ax1.imshow(image[time,:,:])
im2, = ax2.plot(image[0:time,5,5],color=(0,0,1))
if …Run Code Online (Sandbox Code Playgroud) 每次我通过一个适合的程序,我试图刷新我在gui中的一些情节.此外,这些图是在可以调整大小的framw内,因此在调整大小后需要重新绘制轴和标签等.所以,想知道是否有人知道如何使用类似更新图的两侧plot.figure.canvas.copy_from_bbox和blit.这似乎只复制和blit图形区域的背景(绘制线条的位置),而不是图形或图形的边(标签和刻度线的位置).我一直试图让我的图表通过反复试验和读取mpl文档进行更新,但到目前为止,我的代码已经变得非常复杂,例如self.this_plot.canvas_of_plot..etc.etc.. .plot.figure.canvas.copy_from_bbox......这可能太复杂了.我知道我的语言可能有些偏差,但我一直在尝试阅读matplotlb文档,图,画布,图形,情节,图形等之间的差异开始躲避我.所以我的首要问题是:
1 - 如何更新matplotlib图周围的刻度和标签.
其次,既然我想更好地掌握这个问题的答案,
2 - 关于它们在GUI中覆盖的区域,绘图,图形,画布等之间有什么区别.
非常感谢你的帮助.
我在wxpython窗口中有一个matplotlib图/画布.我想在鼠标移动时更新一些关于绘图的信息.我已连接到'motion_notify_event'以获取此信息.
在下面的代码中,绘制了大量随机数据,然后光标的x,y位置显示在窗口的状态栏中.这非常顺利,效果很好.但是,我真的想在情节的顶部显示这些信息.如果取消注释cbUpdateCursor的最后两行,将显示我想要的行为.但是,当这样做时,移动光标的响应时间非常慢(因为绘制被调用并且有大量数据,但必须调用绘制或文本不会更新).
如何加快速度,以便光标位置可以显示在图上,但不能减慢它的速度?我想我可能需要用bbox做点什么?
码:
import wx
import numpy as np
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.widgets import Cursor
from matplotlib.backends.backend_wxagg import \
FigureCanvasWxAgg as FigCanvas, \
NavigationToolbar2WxAgg as NavigationToolbar
class wxPlotting(wx.Frame):
title = 'Test'
def __init__(self):
wx.Frame.__init__(self, None, -1, self.title)
self.time = np.arange(10000)
self.data = np.random.random(10000)
self.sb = self.CreateStatusBar()
self.create_main_panel()
self.axes.plot(self.time, self.data)
self.canvas.draw()
def create_main_panel(self):
self.panel = wx.Panel(self)
self.fig = Figure((5.0, 4.0), dpi=100)
self.canvas = FigCanvas(self.panel, -1, self.fig)
self.axes = self.fig.add_subplot(111)
self.text = self.axes.text(0., 1.005, '', transform …Run Code Online (Sandbox Code Playgroud) 我有一个matplotlib axes实例,我正在为一个AxesImage通过动画制作动画blit.
我想做的是为x轴上的刻度设置动画.我正在更新AxesImage上的数据(以及随后)非常频繁地绘制它的艺术家,并且在每次更新时我想移动一个额外的刻度以突出显示某些东西的位置.这就是我现在正在做的事情:
axis = axes.get_xaxis
im.set_data(new_data)
axis.set_ticks([10,20,30,x,t])
axis.set_ticklabels(["p", "u", "z", "z", "i"])
axes.draw_artist(im)
axes.draw_artist(axis)
Run Code Online (Sandbox Code Playgroud)
虽然我看到刻度线正确更新,但标签不是.我认为轴bbox不包括轴,这可能吗?如果是这样,我该如何设置它的动画?我应该从其他地方复制和恢复吗?
我试图通过使动画运行增加x值来修改和示例.我想更新x轴刻度标签以根据x值更新.
我试图在1.2中使用动画功能(特别是FuncAnimation).我可以设置xlimit但是tick标签没有更新.我也尝试明确设置刻度标签,但这不起作用.
我看到了这个:动画matplotlib轴/刻度,我试图在animation.py中调整bbox,但它不起作用.我对matplotlib相当新,并且对于解决这个问题的实际情况不太了解,所以我将不胜感激任何帮助.
谢谢
"""
Matplotlib Animation Example
author: Jake Vanderplas
email: vanderplas@astro.washington.edu
website: http://jakevdp.github.com
license: BSD
Please feel free to use and modify this, but keep the above information. Thanks!
"""
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
# initialization function: plot …Run Code Online (Sandbox Code Playgroud)