As some others I'm also searching for a convenient way for merging sage Graphics and figures from matplotlib. Actually I don't understand why this is so difficult since Sage uses matplotlib internally. Nevertheless there seems to be no way for combining plots from both packages.
The best way would be to wrap a matplotlib plot into a Sage Graphics object. I really love Sage's plot(...)+plot(...) syntax, but unfortunately there are some important plot types missing (e.g. errorbar plot). Of course one can do all plotting in matlotlib, but it would be more convenient to handle sage objects.
I saw in the sage documentation that one can get a matplotlib figure from a Graphics object, but didn't found a way to draw on it with matplotlib.
Does anyone know any way for combining plots from those packages?
asked Aug 14 '11buergi
73 ● 3 ● 9
Wow hey wait a minute, I found one way to do it. But unfortunately I hoped to get it working the other way round, i.e. converting a matplotlib figure into a
posted Aug 14 '11buergi
73 ● 3 ● 9
The correct answer to this question is Trac 5128. Unfortunately, this has not yet been finished. But once this is done, what you want will be possible.
It's certainly possible in principle, but, as you have seen, it's quite annoying in practice. The main reason is that Sage plots are NOT really mpl plots until we actually save or show them as graphics files; until then they are Sage-y Python objects. Look at the source code file for some plot type, under the
Any contribution to this patch would be very welcome, by the way!
posted Aug 15 '11kcrisman
6784 ● 14 ● 67 ● 152
For some time, I was looking for a way how to generate several sage Graphics() objects and plot them on a matplotlib canvas in an arbitrary arrangement, using .matplotlib() function. It went out not being straightforward. I decided that the solution I've found may be interesting for others as well. The following code produces a plot with a nice inset:
UPD: if figures are drawn strangely, add
to matplotlib() parameters. By default it is 1.0, which may be undesired.
Also, you may want to draw the figure itself, not by Graphics().save() function. Replace the last line with the following:
Asked: Aug 14 '11
Seen: 477 times
Last updated: Jan 19 '12
powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.