matplotlib使用轴位块传输的动画情节不会更新标签 [英] matplotlib animated plot wont update labels on axis using blit

查看:151
本文介绍了matplotlib使用轴位块传输的动画情节不会更新标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用的情节,其中的wxPython在Y轴上的数据限制与数据变化的数据绘制。我想动态更改轴没有重绘整个画布像 canvas.draw(),而我想使用块传输这是我对剧情本身做的。

I am plotting data in a plot using wxPython where the data limits on the y- axis are changing with the data. I would like to change the axis dynamically without redrawing the whole canvas like canvas.draw() rather I'd like to use blitting for this as I do for the plot itself.

我开始工作是不断变化的y轴,和我得到的情节动画的yticks,不幸的是,ylabels都走了,我不能找到解决方案。究其原因是设置 get_yaxis()。set_animated(真)设置轴。

What I got to work is the changing y-axis, and I get the yticks animated with the plot, unfortunately the ylabels are gone and I cant find the solution. The reason is setting the get_yaxis().set_animated(True) setting for the axis.

我放在一起一点点工作的例子在下面。
缺少什么我在这里?

I put together a little working example in the following. What am I missing here?

import matplotlib
matplotlib.use('WXAgg')

import wx
import pylab as p
import numpy as npy
from time import sleep

ax = p.subplot(111)
canvas = ax.figure.canvas
x = npy.arange(0,2*npy.pi,0.01)
line, = p.plot(x, npy.sin(x), animated=True)

ax.get_yaxis().set_animated(True)

def update_line(*args):
    if update_line.background is None:
        update_line.background = canvas.copy_from_bbox(ax.bbox)

    for i in range(20):
        canvas.restore_region(update_line.background)

        line.set_ydata((i/10.0)*npy.sin(x))
        ax.set_ylim(-1*i/5.0-0.5,i/5.0+0.5)

        ax.draw_artist(ax.get_yaxis())

        ax.draw_artist(line)

        canvas.blit(ax.bbox)

        sleep(0.1)
    print 'end'


update_line.cnt = 0
update_line.background = None
wx.EVT_IDLE(wx.GetApp(), update_line)
p.show()

基本上我寻找类似 get_ylabels()。set_animated(真)但我不能找到它。

推荐答案

它看起来像标签绘制但blit的命令不会在将它们复制到画布上,因为边框只包括轴的内部。

It looks like the labels are drawn but the blit command doesn't copy them over to the canvas because the bounding box only includes the inner part of the axes.

对于我来说改变 update_line.background = canvas.copy_from_bbox(ax.bbox) update_line.background = canvas.copy_from_bbox(ax.get_figure( ).bbox) canvas.blit(ax.bbox) canvas.blit(ax.clipbox)使工作。

For me changing update_line.background = canvas.copy_from_bbox(ax.bbox) to update_line.background = canvas.copy_from_bbox(ax.get_figure().bbox) and canvas.blit(ax.bbox) to canvas.blit(ax.clipbox) made it work.

这篇关于matplotlib使用轴位块传输的动画情节不会更新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆