Spyder: Problem with matplotlib in spyder: figure not visible and slow

Created on 17 Feb 2015  Â·  20Comments  Â·  Source: spyder-ide/spyder

_From [email protected] on 2011-12-01T05:23:03Z_

What steps will reproduce the problem?

  1. Run the following simple code snippet:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
y = np.array([1.9, 3.3, 5, 6.3, 8, 6, 2, 3, 2.5, 4])

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y, '-o',label="label")
ax.set_xlabel('DOY')
ax.set_ylabel('flux')
ax.set_title('Photosynthesis rates')
ax.legend()
ax.grid()
plt.show() What is the expected output? What do you see instead? I get a grey or blank figure screen instead of the figure itself (see attachement 'matplotlib-blank screen'). Only after applying an action, eg zooming, the figure becomes visible (see attachement 'matplotlib-after action').
After closing the figure, I also have a problem with the console: it just stays blank (no marks >>>), but it does not hang (you can type in it etc).

In general, my impression is also that matplotlib is running very slow within spyder (I don't have the problem with matplotlib in python from the terminal). What version of the product are you using? On what operating system? Ubuntu 11.10, Spyder 2.1.1

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=859_

2–5 stars Bug

Most helpful comment

_From [email protected] on 2011-12-01T05:44:05Z_

I don't find the option.

Attachment: preferences.png

All 20 comments

_From [email protected] on 2011-12-01T02:24:07Z_

The attachments. The third 'matplotlib-console problem' illustrates the state of the console after closing the figure.

Attachment: matplotlib-blank sreen.png matplotlib-after action.png matplotlib-console problem.png

_From [email protected] on 2011-12-01T02:27:20Z_

To illustrate that the console is still working, but only no marks >>> are shown, which is very annoying.

Attachment: matplotlib-console problem2.png

_From [email protected] on 2011-12-01T02:31:24Z_

Sorry for all the comments, but I just tested it with the IPython console it spyder, and there I have no problems. So it is only with the python console.

_From pierre.raybaut on 2011-12-01T05:34:22Z_

Could you please try again in the standard Python console but with the "Replace PyQt input hook by Spyder's" option turned on (Preferences > Console > External modules) ?

_From [email protected] on 2011-12-01T05:44:05Z_

I don't find the option.

Attachment: preferences.png

_From pierre.raybaut on 2011-12-01T06:10:31Z_

I'm sorry I forgot that this option is experimental on Linux, so hidden.
But I've just tested: I'm able to reproduce this bug and I don't know where it comes from yet.

_From pierre.raybaut on 2011-12-02T07:23:43Z_

This bug in standard Python interpreter is now fixed on current dev version. Please check if you can.

Status: Fixed

_From pierre.raybaut on 2011-12-02T07:23:45Z_

This bug in standard Python interpreter is now fixed on current dev version. Please check if you can.

_From [email protected] on 2011-12-03T03:39:55Z_

I tested it, and on my machine it is only partly fixed. The console problem is fixed, but matplotlib still starts with a blank or grey screen.

But I will take a closer look this evening, because maybe it has to do because I have also the older version on my computer? I didn't remove 2.1.1, and in the internal console I got a warning message:

/usr/lib/python2.7/dist-packages/pygments/plugin.py:39: UserWarning: Module spyderplugins was already imported from /home/joris/spyderlib/spyderplugins/init.py, but /usr/local/lib/python2.7/dist-packages/spyder-2.1.1-py2.7.egg is being added to sys.path
import pkg_resources
/usr/lib/python2.7/dist-packages/pygments/plugin.py:39: UserWarning: Module spyderlib was already imported from /home/joris/spyderlib/spyderlib/init.py, but /usr/local/lib/python2.7/dist-packages/spyder-2.1.1-py2.7.egg is being added to sys.path
import pkg_resources

_From pierre.raybaut on 2011-12-03T09:40:08Z_

In principle, if you start Spyder from the source package by executing the bootstrap script, there should not be any version mixup.

_From [email protected] on 2011-12-03T11:01:50Z_

OK.
So I can confirm that the matplotlib figure still appears with a grey or white screen (it varies a bit, sometime grey, sometimes white), but that the problem with the console is solved.

I also checked the box "Replace PyQt input hook by Spyder's", but that does not solve it.

_From pierre.raybaut on 2011-12-03T23:57:08Z_

I can't try again right now but two days ago I tried on an Ubuntu 10.04 LTS and I was able to reproduce the console issue (which is now solved) but not the matplotlib refresh issue.

Are you still getting the impression that Matplotlib is slower inside Spyder than outside?
(that I can't reproduce neither)

Status: Started

_From [email protected] on 2011-12-04T02:30:48Z_

I compared matplotlib in spyder and in plain python from terminal (Ubuntu 11.10, Matplotlib 1.0.1, Python 2.7.2). I am not certain it is slower in Spyder, but is certainly more choppy (or shaky, jumpy, I don't know exactly the right word). And because of this it gives the impression to be slower.

But in the terminal, python uses the default TkAgg backend I think, and in Spyder the Qt4Agg. When I unchecked the option 'GUI backend: 'Qt4Agg'' and restarted Spyder, and then the figure (with the less pretty toolbar below the figure) responded the same as in the terminal (and was directly visible, so no blank screen). So I think it has something to do with the 'extras' spyder adds to matplotlib figure window.

With trying out that, I also discovered another issue (I filed it: issue #870 ). Because the option "Replace PyQt input hook by Spyder's" was still checked, and when I unchecked Qt4Agg, matplotlib didn't respond at all.

_From pierre.raybaut on 2011-12-04T03:16:01Z_

And have you tried the Qt4Agg backend outside Spyder?

If you disable the option "Patch Matplotlib figures", Spyder should not add any extra to Matplotlib except selecting the backend if the option is checked.
So have you tried to let the option "Set backend to Qt4Agg" checked and uncheck the "Matplotlib patch" option?

_From [email protected] on 2011-12-04T03:34:29Z_

Yes, I tried the Qt4Agg backend outside Spyder, but is seems visually the same as the TkAgg backend (unless I did something wrong), and the performance seems also the same.

But the option "Patch Matplotlib figures" was already disabled. I tried both checked and unchecked, and there is no difference. In both occasions there is an extra button with figure options.

_From pierre.raybaut on 2011-12-04T04:40:58Z_

To be sure that you are really using the Qt4Agg (outside Spyder), open a standard Python interpreter and do the following:

import matplotlib
matplotlib.use('Qt4Agg')
from pylab import *
ion()

...and then, start your tests of interactive plotting.

_From [email protected] on 2011-12-05T03:04:15Z_

Aha, yes I did something wrong (probably because I already imported pyplot, the changing of the backend had no effect). It is difficult to say, but I think that there no real difference between the Qt4Agg in plain python or in spyder (TkAgg seems to look a little bit smoother on my computer when you zoom and drag the figure).

But I found a possible clue for the blank figure region issue. It has something to do with the scientific startup and my use of matplotlib. I discovered it because I quickly made a figure (in pylab mode) and noticed that the figure was shown directly (no initial blank screen).

So if I run:

x = np.arange(10)
y = np.array([1.9, 3.3, 5, 6.3, 8, 6, 2, 3, 2.5, 4])

plot(x, y)

I see the figure immediately.
If I run:

x = np.arange(10)
y = np.array([1.9, 3.3, 5, 6.3, 8, 6, 2, 3, 2.5, 4])

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
plt.show()

I get a blank/grey screen.

I tried it also in:

  • spyder python console without scientific startup.

    • without importing pylab: it behaves normal

    • with from pylab import *: it behaves still normal

    • with ion(): problem with blank screen

  • terminal (outside spyder) with first the same inputs as done in the scientific startup, but here I have no problems. So not after importing pylab and ion().

So my conclusing would be that there is a problem with the combination of the interactive mode and the pyplot interface in spyder (only in spyder, not with python in terminal). When I turned interactive mode off with ioff(), I have no problem anymore (so this is a good solution for me if I am the only one experiencing this, or otherwise to turn off the scientific startup).

Do you have any idea what could be the reason?

_From pierre.raybaut on 2011-12-24T06:01:28Z_

It would certainly be worth trying the latest Matplotlib version (1.1.0+) and the latest Spyder version (2.1.5+).

Anyway, I'm marking this issue as closed -- but it does not prevent us from continuing this discussion, of course.

Status: Fixed

I have changed the preferences in tools and run the command: %matplotlib auto

Follow: https://stackoverflow.com/questions/23585126/how-do-i-get-interactive-plots-again-in-spyder-ipython-matplotlib

This solved the problem and I can see the plots now.

woha, i just spent hours figuring out why i get black windows instead of matplotlib plots via x11 in a remote-kernel... (while all works out fine in an ordinary ssh terminal)

I've installed several x-server tools, tested all possible matplotlib backends and finally arrived here just to find that executing %matplotlib auto just magically does the trick!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spyder-bot picture spyder-bot  Â·  3Comments

hedeqing picture hedeqing  Â·  3Comments

JesterEE picture JesterEE  Â·  3Comments

ok97465 picture ok97465  Â·  3Comments

danieltomasz picture danieltomasz  Â·  3Comments