Example #1
0
 def __init__(self, data):
     self.data = Table(data)
     self.views = {}
     self.selections = {}
     self._next_select = []
Example #2
0
    def __init__(self,
                 data,
                 xt,
                 yt=None,
                 ax=None,
                 f1d=plt.hist,
                 f2d=plt.plot,
                 f1d_kwargs={},
                 f2d_kwargs={},
                 idx=None,
                 name=None,
                 selections=None,
                 parent=None):

        self.axes = ax or plt.gca()

        if not isinstance(self.axes, Axes):
            raise ValueError(
                'type {} not managed, only matplotlib.axes.Axes are handled'.
                format(type(ax)))

        #get the data into a Table format for fast interactions
        if not isinstance(data, Table):
            self.data = Table(data)
        else:
            self.data = data

        #define axes and precompute the data
        self.xt = xt
        self.yt = yt
        self.x = self.data.evalexpr(self.xt)
        if yt is not None:
            self.y = self.data.evalexpr(self.yt)
        else:
            self.y = None

        #set the default values
        self.name = name  # or ax.name
        self.canvas = self.axes.figure.canvas  # keep the current canvas for interactions
        self.fig = self.axes.figure  # keep the current figure ling
        self.selections = selections or {}  # indices of the selections
        self._draws = {}  # keep track of existing representations
        self._next_select = [
        ]  # set when using lasso interaction to define the plotting
        self.parent = parent  # used when within a DataFrame
        self._lasso = False  # set during lasso interaction

        #update canvas
        self.xlabel(xt.replace('_', ' '))
        if yt is not None:
            self.ylabel(yt.replace('_', ' '))

        #add initial plot
        if len(self.selections) == 0:
            idx = idx or range(self.data.nrows)
            self.add_sample(idx, f1d, f2d, f1d_kwargs, f2d_kwargs)
        else:
            self.pchanged()

        #connect to callbacks
        self.canvas.mpl_connect('pick_event', self.onpick)
        self.canvas.mpl_connect('button_press_event', self.onpress)
        self.canvas.mpl_connect('button_release_event', self.onrelease)