所有这一切一开始肯定会相当混乱!
首先,如果您要链接滴答声等,则使用 blitting 没有多大意义。如果只有某些事情发生变化,Blitting 只是一种避免重新绘制所有内容的方法。如果一切都在变化,那么使用 blitting 就没有意义了。只是重新绘制情节。
基本上,你只是想要fig.canvas.draw()
或plt.draw()
无论如何,要回答您的第一个问题,在大多数情况下,您不需要手动更新它们。如果您更改轴限制,它们会自行更新。您遇到了问题,因为您只是在轴内部而不是重绘绘图。
至于你的第二个问题,一个很好的详细概述是Matplotlib用户指南的艺术家教程。
简而言之,有两个独立的层。一种处理将事物分组到绘图时您会担心的部分(例如图形、轴、轴、线等),另一种处理一般的渲染和绘图(画布和渲染器)。
您可以在 matplotlib 图中看到的任何内容都是Artist
. (例如文本、线条、轴,甚至图形本身。)艺术家a)知道如何绘制自己,并且b)可以包含其他艺术家。
对于艺术家自己绘制,它使用渲染器(您几乎永远不会直接接触的特定于后端的模块)在FigureCanvas
又名“画布”(基于矢量的页面或像素缓冲区的抽象)上绘制。要在图中绘制所有内容,请调用canvas.draw()
.
Because artists can be groups of other artists, there's a hierarchy to things. Basically, something like this (obviously, this varies):
Figure
Axes (0-many) (An axes is basically a plot)
Axis (usually two) (x-axis and y-axis)
ticks
ticklabels
axis label
background patch
title, if present
anything you've plotted, e.g. Line2D's
Hopefully that makes things a touch clearer, anyway.
If you really do want to use blitting to update the tick labels, etc, you'll need to grab and restore the full region including them. This region is a bit tricky to get, because it isn't exactly known until after draw-time (rendering text in matplotlib is more complicated than rendering other things due to latex support, etc). You can do it, and I'll be glad to give an example if it's really what you want, but it's typically not going to yield a speed advantage over just drawing everything. (The exception is if you're only updating one subplot in a figure with lots of subplots.)