[Matplotlib-users] Real-time graph, redrawing a changing Y axis

Jody Klymak jklymak at uvic.ca
Wed Jun 29 18:36:53 EDT 2016

> On Jun 29, 2016, at  15:12 PM, John Ladasky <jladasky at itu.edu> wrote:
> I am using MPL 1.4.2, Python 3.4, and Ubuntu 15.04.  I am developing a program which displays real-time data.  On each update cycle, the graph needs to adjust the y-axis scale.  I have code that mostly works, but when it re-renders the y-axis, it is not completely erasing the old one.  I get tick labels written on top of each other, until everything is an unreadable smear, like this:

I think thats because `redraw_in_frame()` doesn’t update any of the axes data…

Have you looked into the animation API?  Its meant for this sort of thing, and seems pretty snappy.  Most of what you are doing below would just go into the `animate` function. 

http://matplotlib.org/examples/animation/simple_anim.html <http://matplotlib.org/examples/animation/simple_anim.html>

Cheers,   Jody

> <For matplotlib-users.png>
> Here is the relevant part of my update method:
> self.plot.set_data(self.x[:size], self.y[:size])
> lo = self.y[:size].min()
> hi = self.y[:size].max()
> if hi - lo > 150:
>     self.ax.set_ylim(lo-25, hi+25)
> else:
>     mid = self.y[:size].mean()
>     self.ax.set_ylim(mid-100, mid+100)
> self.ax.relim()
> self.ax.autoscale_view(None, False, True)
> self.ax.redraw_in_frame()
> # Something which erases the Y axis should go here?
> self.ax.get_yaxis().draw(self.parent.get_renderer())
> I think that the details of setting the Y limits are unimportant, but I've included that code anyway, so that you can see my set_data() method call at the top, and you can also see that I'm continually adjusting the Y range to track the data.  
> I think that I am searching for a method in the axis class which would erase the previously drawn tick marks and labels.  So far, I haven't found one.  It would replace the comment line in my code.
> I am trying to avoid redrawing the entire canvas on which this plot is embedded, since there are several other live data plots besides the one I have shown. The first version of my program did a full redraw, and it took over 150 milliseconds to complete an update call.  That's too slow for my needs.
> Thanks for any help you can provide!
> -- 
> John J. Ladasky Jr., Ph.D.
> Research Scientist
> International Technological University
> 2711 N. First St, San Jose, CA 95134 USA
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160629/5c2ac08c/attachment.html>

More information about the Matplotlib-users mailing list