Suppress printed output from PyPlot

800 views
Skip to first unread message

gdmsl

unread,
Feb 13, 2015, 4:58:44 AM2/13/15
to julia...@googlegroups.com
Hi,

I need to run a script which generates a large number of plots using the PyPlot module but the output of the script is filled with messages from PyPlot. How can i suppress this output?
Here is an example:

julia> using PyPlot
INFO: Loading help data...

julia> pygui(false)
false

julia> plot(rand(10),rand(10));
Figure(PyObject <matplotlib.figure.Figure object at 0x7f7979d24dd8>)
Figure(PyObject <matplotlib.figure.Figure object at 0x7f7979d24dd8>)

I really need to suppress output like "Figure(PyObject <matplotlib.figure.Figure object at 0x7f7979d24dd8>)"

Thanks in advance,
Guido

Steven G. Johnson

unread,
Feb 13, 2015, 4:16:47 PM2/13/15
to julia...@googlegroups.com
On Friday, February 13, 2015 at 4:58:44 AM UTC-5, gdmsl wrote:
julia> plot(rand(10),rand(10));
Figure(PyObject <matplotlib.figure.Figure object at 0x7f7979d24dd8>)
Figure(PyObject <matplotlib.figure.Figure object at 0x7f7979d24dd8>)

I really need to suppress output like "Figure(PyObject <matplotlib.figure.Figure object at 0x7f7979d24dd8>)"

The plot command (and similar) displays its output as a side effect (think of it as a "println" statement, but via "display").   In the REPL, the default "display" backend just calls `print`.   You can suppress this in two ways:

1) You could define your own display backend that silently ignores `Figure` objects, and push it onto the display stack (see the Multimedia I/O section of the manual.

2) You could wrap your plot commands in withfig:

     f = figure()
     withfig(f) do
          .... plot commands ...
     end;

The withfig command converts the plot results from a side effect into a return value (which you can suppress with a semicolon).   It was intended for use with the Interact package, but should work as well here.

Guido Masella

unread,
Feb 23, 2015, 6:52:25 AM2/23/15
to julia...@googlegroups.com
Hi,

thank you for the tips but the second method return an error:

ERROR: IJulia not defined
 in withfig at /home/gdmsl/.julia/v0.3/PyPlot/src/PyPlot.jl:547

Steven G. Johnson

unread,
Feb 23, 2015, 1:05:55 PM2/23/15
to julia...@googlegroups.com


On Monday, February 23, 2015 at 6:52:25 AM UTC-5, gdmsl wrote:
thank you for the tips but the second method return an error:

Oh, right, withfig currently only works with IJulia (which has a display queue and an "undisplay" function to remove things from the queue).    It won't work with the REPL.  So, probably you need the other solution: implement and push a (trivial) custom display backend then.
Reply all
Reply to author
Forward
0 new messages