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

John Ladasky jladasky at itu.edu
Wed Jun 29 18:12:36 EDT 2016

Hello everyone,

Thomas Caswell has kindly directed me from the old Matplotlib-users mailing
list on Sourceforge, to this address at Python.org.  I submitted this post
once before to this mailing list, yesterday, before I found the web page
for subscribing.  If a duplicate message should appear, please accept my

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:

[image: Inline image 1]

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)
    mid = self.y[:size].mean()
    self.ax.set_ylim(mid-100, mid+100)
self.ax.autoscale_view(None, False, True)
# Something which erases the Y axis should go here?

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

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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160629/f98f94c3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: For matplotlib-users.png
Type: image/png
Size: 14864 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160629/f98f94c3/attachment-0001.png>

More information about the Matplotlib-users mailing list