Ask Your Question
1

How to plot a zoomed part in a matplotlib figure in sage?

asked 2010-08-19 13:55:29 +0100

twk gravatar image

Hi, I'm trying to zoom one part of my figure in Matplotlib. In the Matplotlib-Galery, I found this nice example using mpl_toolkits.axes_grid.inset_locator

http://matplotlib.sourceforge.net/plo...

The result is http://matplotlib.sourceforge.net/plo...

which is pretty much what I need.

Does anybody know how to do this in sage? I didn't manage to use this function in sage. (In fact, I even didn't find it)

Thanks!

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
1

answered 2010-08-19 14:47:20 +0100

kcrisman gravatar image

Apparently our Matplotlib (matplotlib-0.99.3) does not have mpl_toolkits.axes_grid1, which is needed for that example. The same example would work in Sage if you used mpl_toolkits.axes_grid, except plt.show() doesn't necessarily work from within Sage, so for instance plt.savefig('test.png') would work to save it in your home directory.

edit flag offensive delete link more

Comments

See http://trac.sagemath.org/sage_trac/ticket/9221 for the upgrade trac ticket (upgrade to matplotlib 1.0)

Jason Grout gravatar imageJason Grout ( 2010-08-19 23:58:44 +0100 )edit

See trac #9221 for the upgrade trac ticket (upgrade to matplotlib 1.0)

Jason Grout gravatar imageJason Grout ( 2010-08-19 23:59:09 +0100 )edit
2

answered 2010-08-19 15:10:29 +0100

From what I understand the Sage Notebook displays a plot if a .png file is created in the directory corresponding to the cell. Thus, plt.savefig('.') also works. Also, be sure to set hold(False) if you want the same behavior as Sage's plot command. Otherwise, your plots will continue to overlap.

Since I use Pylab extensively for numerics, I have a published Sage Notebook here demonstrating plotting in Sage using matplotlib trough Pylab: http://uw.sagenb.org/home/pub/9/. You'll get similar behavior when you use import matplotlib.pyplot instead.

(I would've posted this as a comment to kcrisman's answer above but ASKBOT is giving some strange errors.)

edit flag offensive delete link more
0

answered 2010-08-19 16:53:50 +0100

twk gravatar image

Hi, Thanks for your answers. In the mean time, I tried on my own and made it. Unfortunately, I had to use some very dirty tricks and finally just copied the file "inset_locator.py" from "/usr/lib/pymodules/python2.6/mpl_toolkits/axes_grid" to 'sage/local/lib/python2.6/site-packages/mpl_toolkits/axes_grid'

I don't know about possible bugs, but I got the needed result. By the way...how can I get this message to view the underlines _ ? Maybe a topic for a new question..

Thanks, Tobi

edit flag offensive delete link more
0

answered 2010-08-19 16:58:12 +0100

twk gravatar image

Hi, Thanks for your answers. In the mean time, I tried on my own and made it. I wanted to answer my own question but I get ugly errors when I do so...

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: 2010-08-19 13:55:29 +0100

Seen: 4,666 times

Last updated: Aug 19 '10