I have a module that will be used in iPython.
I would like the user to enter everything necessary to create the graph-x, y, label, line width, etc.
This way the user can do something like this:
In[1] import this_script
In[2] x=range(0,10)
In[3] y=x
In[4] magically_exposed_function plot(x,y,'r+', linewidth=2)
This means that my function gets a line graph (x, y, 'r +', line width = 2). This can be analyzed by the x and y values found in the iPython namespace using ip.user_ns, but I'm still stuck with what to do with "r +" and line width = 2. Ideally, I would like to be able to:
a) import the entire iPython namespace so that I have available x and y values and
b) throw out the whole line in plot ()
As for b), having something like:
plot_string = x, y, 'r+', linewidth = 2
plot(plot_string)
, , .
? ?
(x, y), ?
, , :)
!
--Erin
[EDIT] , :
import matplotlib
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanv
from matplotlib.figure import Figure
import IPython.ipapi
ip = IPython.ipapi.get()
import sys
class WrapperExample(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, None, -1)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.axes.plot(*args, **kwargs)
self.canvas = FigCanv(self, -1, self.figure)
def run_me(*args, **kwargs):
""" Plot graph from iPython
Example:
In[1] import script
In[2] x=range(0,10)
In[3] y=x
In[4] run_me x y
"""
app = wx.PySimpleApp()
wrap = WrapperExample(*args, **kwargs)
wrap.Show()
app.MainLoop()
ip.expose_magic("run_me", run_me)
[EDIT] , , :
import wx
import matplotlib
from pylab import *
import IPython.ipapi
ip = IPython.ipapi.get()
class MainCanvas(wx.Frame):
def __init__(self, *args):
self.figure = plt.figure()
self.axes = self.figure.add_subplot(111)
self.axes.plot(*args)
show()
def run_this_plot(self, arg_s=''):
""" Run
Examples
In [1]: import demo
In [2]: rtp x y <z>
Where x, y, and z are numbers of any type
"""
args = []
for arg in arg_s.split():
try:
args.append(self.shell.user_ns[arg])
except KeyError:
raise ValueError("Invalid argument: %r" % arg)
mc = MainCanvas(*args)
ip.expose_magic("rtp", run_this_plot)