1

I am a newbie of matplotlib.

Recently I am using #WinPython-64bit-3.3.2.1# on #Win-7 64bit# and When I typed codes on the IPython Qt Control as below:

In [1]: plot(range(3))    
Out[1]: [<.matplotlib.lines.Line2D at 0x64ae390>] 
% There is a plot. 
In [2]: show() 
%nothing happened.

There should be a plot after show. But nothing happed, no error message. And the savefig() will only save a blank fig. I tried the solution of matplotlib does not show my drawings although I call pyplot.show() by setting backends = 'GtkAgg' or 'QtAgg', but it did not work.

Thanks for your advice. :)

Updata1: The 'WinPython Interpreter.exe' is used instead of 'IPython QT Console.exe'. Then I typed the same code and the show() worked. The backend is set to GtkAgg.

I think the reason is as below:

Since WinPythonInterpreter is a command window, it need a new window to display the plot. The IPython supports interactive data visualization, it does not need another window.

Updata2: I just fount that the gcf() returned different references in the QT Console, and it returned the same reference in WinPython Interpreter. Maybe this is the problem point.

Community
  • 1
  • 1
Steve
  • 1,448
  • 11
  • 18
  • `setting backends = 'GtkAgg' or 'QtAgg', but it did not work.` Did you get errors or just a blank figure? What is your default backend? – Francesco Montesano Jul 04 '13 at 09:29
  • Did you start in pylab mode? Could you try that if not using the `--pylab` command line switch (in which case you shouldn't need the show statement anyway as it's 'interactive') – jmetz Jul 04 '13 at 09:30
  • @FrancescoMontesano , I set the backends in the matplotlibrc file and nothing has changed. The default backends shall be the original: GTKAgg – Steve Jul 04 '13 at 13:26
  • does it work if you do `plot(list(range(3)))`? – Francesco Montesano Jul 04 '13 at 13:38
  • Hi, @mutzmatron , I am using the WinPython on Windows and not sure whether it is in pylab mode. So i tried 'IPython Console Qt --pylab' in the cmd, nothing changed. – Steve Jul 04 '13 at 13:39
  • hi, @FrancescoMontesano , I did not try plot(list(range(3))). But When I do plot(range(3)), there will be Output and a plot. – Steve Jul 04 '13 at 13:42
  • I see that you're using python 3.3. I don't use it and I don't have matplotlib for python 3, but I know that `range` returns an iterator and not a list. I don't know if this can cause the problem that you have – Francesco Montesano Jul 04 '13 at 13:48
  • Thanks, @FrancescoMontesano. I will try 'list(range(3))' when i get the computer. But I do not know how to make show() works.:D – Steve Jul 04 '13 at 14:08
  • @FrancescoMontesano, `list(range(3))` works, it will output a straight line. – Steve Jul 05 '13 at 01:30

1 Answers1

0

The WinPython IPython QT console appears to default to pylab with the inline backend as mutzmatron suggested in the comments.

It can be a little confusing to know what mode Matplotlib is working in see Matplotlib pylab and pyplot: how they are related?

I tend to use the Python distribution Anaconda it's QTConsole doesn't preload pylab by default so you can import pyplot and use show(), With WinPython you can launch the IPython QT console like this by going to the WinPython*\python*\Scripts directory with the windows command prompt and launching ipython3.exe qtconsole

import matplotlib.pyplot as plt
plt.plot(range(3))
plt.show()

Although that halts the execution in the IPython QT console when plot is open. You can detect which backend is being used by plt.get_backend(), the Anaconda IPython QT console uses QT4Agg on my Windows 7 install.

seumas
  • 512
  • 1
  • 6
  • 17
  • @semuas, Yes, the WinPython IPython QT console do preload pylab and matplotlib. But I dont think that's the reason. Maybe the gcf() returns different references cause this problem. I will update the details in my question. – Steve Jul 09 '13 at 09:47