Ask Your Question

buergi's profile - activity

2014-05-30 10:16:56 +0200 received badge  Great Question (source)
2013-07-08 10:03:49 +0200 received badge  Famous Question (source)
2012-09-22 05:49:34 +0200 received badge  Notable Question (source)
2012-04-03 20:16:48 +0200 received badge  Popular Question (source)
2012-01-30 06:23:49 +0200 received badge  Scholar (source)
2012-01-30 06:23:49 +0200 marked best answer How to if python script runs in notebook?
2012-01-27 11:32:43 +0200 received badge  Editor (source)
2012-01-27 11:30:53 +0200 asked a question How to if python script runs in notebook?

I wrote a small piece of python code which i use as a module in python as well as in a worksheet in sage notebook. Since this script uses pyplot i'd like to do something like

if in_notebook: pyplot.savefig('fig')
else: pyplot.show()

How can i find out where the script is running in?

At the moment i'm querying sys.executable, but i guess this can be done better.

2011-12-15 05:18:03 +0200 received badge  Supporter (source)
2011-10-08 07:28:30 +0200 received badge  Good Answer (source)
2011-08-15 10:08:15 +0200 received badge  Good Question (source)
2011-08-15 10:08:11 +0200 received badge  Nice Answer (source)
2011-08-15 09:47:12 +0200 received badge  Nice Question (source)
2011-08-14 17:03:37 +0200 received badge  Student (source)
2011-08-14 17:03:34 +0200 received badge  Self-Learner (source)
2011-08-14 17:03:34 +0200 received badge  Teacher (source)
2011-08-14 16:52:08 +0200 answered a question combine sage plot with matplotlib

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

import matplotlib.pyplot as pl
pl.errorbar(xs,ys,yerr=dys,fmt="ro")
plot(lambda x:f(x),(0,200)).matplotlib(figure=pl.gcf())
pl.savefig('myplot')
2011-08-14 16:39:54 +0200 asked a question combine sage plot with matplotlib

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?