How to animate ticks on the x-axis?

I have an instance of matplotlib axes inside which I AxesImage through a blit ting.

What I would like to do is animate the ticks on the X axis. I update the data about AxesImage (and subsequently), drawing his artist quite often, and with each update I would like to move one additional tick to highlight the position of something. This is what I'm doing now:

 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) 

Although I see the checkboxes being updated correctly, the shortcuts are not. I think the Bbox axis does not include an axis, is this possible? If so, how can I revive it? Should I backup and restore from somewhere else?

+5
source share
1 answer

The bbox axes do not contain anything outside the "inside" axes (for example, it does not have labels for labels, title, etc.)

One quick way around this is to simply capture the entire area of ​​the piece when you hit. (For example, background = canvas.copy_from_bbox(fig.bbox) )

This can cause problems if you have several subplots and only want to revive one of them. In this case, you can do something along the lines of background = canvas.copy_from_bbox(ax.bbox.expanded(1.1, 1.2)) . However, you will need to evaluate the odds you need.

If you need an exact label for shortcuts, this is a little trickier. The easiest way is to loop through ticklabel objects and get union with ax.bbox . You can do this in one layer: ax.bbox.union([label.get_window_extent() for label in ax.get_xticklabels()]) .

Anyway, one of these three options should do what you need, I think.

+4
source

Source: https://habr.com/ru/post/949056/


All Articles