3

From past experience and the http://matplotlib.org/users/shell.html page, my understanding is I should use the TkAgg backend. I'm finding that TkAgg isn't updating plots in matplotlib 1.5.1 or 1.5.0, whereas it was in matplotlib 1.4.3. I am running this script:

import time
import matplotlib as mpl
print mpl.__version__
mpl.rcParams['backend'] = 'TkAgg'

import matplotlib.pyplot as plt
plt.ion()

plt.figure(3)

for xx in range(3):
    plt.ioff()
    plt.plot([1,3,34],[3,4+xx,3])
    plt.draw()
    plt.ion()
    print "sleeping 1 sec"
    time.sleep(1)

and under 1.4.3, I get a new line added to the plot each second, whereas in 1.5.1, the figure shows, but no plot is drawn. It should be the former shouldn't it? Or is something wrong with my use of ioff/draw/ion, or is there some other way to do this that will work with matplotlib 1.5.1?

My environment is linux red hat 7, python 2.7.11, and I'm using anaconda conda to create the two different environments, that is

conda create --name matplotlib-1.5.1 matplotlib=1.5.1
conda create --name matplotlib-1.4.3 matplotlib=1.4.3

So maybe it is a problem with the anaconda packaging? When I list the packages in those two environments, everything is the same except that matplotlib-1.4.3 has a dependency on py2cairo 1.10.0, whereas matplotlib 1.5.1 has a dependency on py2cairo 1.10.0, and on something new called cycler 0.9.0. I didn't see anything in the http://matplotlib.org/devdocs/users/whats_new.html page that suggested a change here.

4
  • I know this is not an answer to your question but, if you are really into interactive real-time fast plotting, you should have a look at PyQtGraph (pip install pyqtgraph, import pyqtgraph.examples, pyqtgraph.examples.run()). ;-) Commented Feb 18, 2016 at 9:38
  • I think pyqtgraph is great for speed, but there's less documentation, and maybe less development? I heard the developers were off to something new? Commented Feb 18, 2016 at 14:33
  • 2
    There is less development, of course, as it is less used/known. But PyQtGraph is still being developed. The "something new" project that you may be referring to is Vispy, but it wont replace PyQtGraph, rather it would be integrated in PyQtGraph when the time comes. ;-) Commented Feb 18, 2016 at 14:47
  • Thanks, we switched to PyQtGraph for fast feedback, but then heard about Vispy and got nervous. If curious - it is used under the hood in this project: psmon it uses zmq to send plot data from jobs on a cluster (with no X connection) to machines that can view the plots Commented Feb 18, 2016 at 15:06

1 Answer 1

3

This didn't draw for me on matplotlib 1.4.3. I'd suggest a few changes, including adding plt.show() before and using plt.pause(1.) instead of time.sleep() which may play better with the new matplotlib. Does the following work as expected,

import matplotlib as mpl
print mpl.__version__
mpl.rcParams['backend'] = 'TkAgg'

import matplotlib.pyplot as plt

plt.figure(3)
plt.ion()
plt.show()

for xx in range(3):
    plt.plot([1,3,34],[3,4+xx,3])
    plt.draw()
    print("sleeping 1 sec")
    plt.pause(1.)

I know this is more of a comment but seemed easier to post the code like this (and it may help fix).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it works! The pause() function seems key for activating the backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.