Ask Your Question
3

GUI backend MATPLOTLIB in Sage

asked 2014-03-25 00:45:29 -0500

gundamlh gravatar image

updated 2017-01-08 05:19:04 -0500

FrédéricC gravatar image

Dear all,

  • UPDATED:

How can one export the data (a object) 'matplotlib.figure.Figure' the namespace of Sagemath to IPython? Can the data be saved in a format (not png, pdf, etc.) that can be opened in IPython using the function show()?

Here is a related Question. I have followed this instruction step by step, every step was successfully executed without any error report/message. However I couldn't invoke TkAgg as Backend of Sagemath nor IPython.


Has SAGE a GUI back-end as MATPLOTLIB, on which one can zoom, select points etc.?

for example,

    sage: bodes['entire']
    <matplotlib.figure.Figure at 0x91ac950>
    sage: bodes['entire'].show() 
    # It doesn't work and a Warning occurs. 
    /opt/sagemath/sage-6.1.1-x86_64-Linux/local/lib/python2.7/
    site-packages/matplotlib/figure.py:362: UserWarning: matplotlib is 
    currently using a non-GUI backend, so cannot show the figure 
    "matplotlib is currently using a non-GUI backend, "
    sage: f = bodes['entire']
    sage: f.savefig('./figures/entire.png') 
    # I can only save my plotting in formats : png, pdf, etc..

Thank you all in advance!

edit retag flag offensive close merge delete

Comments

Only steps 6 to 9 are important because by default matplotlib is built without GUI support within Sage. It worked for me. Try again with removing all related to TkAgg.

vdelecroix gravatar imagevdelecroix ( 2014-03-27 10:55:49 -0500 )edit
vdelecroix gravatar imagevdelecroix ( 2014-04-13 20:44:58 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2014-04-13 20:57:53 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I am just repeating the solution of N. Dunfield at http://www.math.uiuc.edu/~nmd/temp/tkplot.py for backup

Matplotlib does all the 2D graphics for Sage, but unfortunately none of its GUI backends are compiled by default. The following suffices to compile the Tk backend on Linux, provided you have the tk-dev(el) package installed:

$ export SAGE_MATPLOTLIB_GUI=yes
$ sage -f matplotlib

This doesn't work on OS X because in addition to TkAgg, Sage will try to compile the native Mac backend, which fails since Sage doesn't include an Objective-C compiler. For OS X, download the source tarball for matplotlib, and then do

$ cd matplotlib-*
$ sage -sh echo '[gui_support]' >> setup.cfg
$ echo 'macosx=false' >> setup.cfg
$ python setup.py install

Alternatively use the patched spkg (which has a modified make-setup-config.py file at the top leve ) available at http://dunfield.info/temp/matplotlib-...

Note that the TkAgg backend will be compiled against one's current version of Tk, which might not be the one that Sage is linked against. So inaddition one may need to recompile the Tkinter module via

$ sage -f python

Then any matplotlib command will work:

sage: from numpy import arange, sin, pi
sage: import matplotlib.pyplot as plt
sage: X = arange(0.0, 2*pi, 0.01)
sage: plt.plot(X, sin(X))
sage: plt.show()

Something seems to be broken since version 5.11, the GUI blocks the console. In order to correct this behaviour one solution is to use the following (see also #15152):

sage: import IPython.lib.inputhook as ih
sage: ih.clear_inputhook()

Note that after that command, the magic %attach will be broken.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-03-25 00:45:29 -0500

Seen: 2,478 times

Last updated: Apr 13 '14