Esempio n. 1
0
    def plot_XYZ(self, cmap="Blues", plot="image", **kwargs):
        """
        This is 8 million times faster than pseudocolor I guess, but it won't handle unevenly spaced stuff.

        You need to generate X, Y and Z first, probably using get_XYZ.

        cmap    Name of the matplotlib cmap to use
        plot    Type of plot, "image" for fast colorplot, "mountains" for slow 3d plot
        """

        # if we don't have the data, tell the user
        if self.X == None or self.Y == None or self.Z == None:
            print "You haven't assembled the surface data yet. Use get_XYZ first!"
            return

        # try the user's colormap
        try:
            colormap = eval("_pylab.cm."+cmap)
        except:
            print "ERROR: Invalid colormap, using default."
            colormap = _pylab.cm.Blues

        # at this point we have X, Y, Z and a colormap, so plot the mf.
        f=_pylab.gcf()
        f.clear()

        if plot.lower() == "mountains":
            X, Y = meshgrid(self.X, self.Y)
            a = Axes3D(f)
            a.plot_surface(X, Y, self.Z, rstride=2, cstride=2, cmap=colormap, **kwargs)

        else:
            # assume X and Y are the bin centers and figure out the bin widths
            x_width = abs(float(self.X[-1] - self.X[0])/(len(self.X)-1))
            y_width = abs(float(self.Y[-1] - self.Y[0])/(len(self.Y)-1))

            # do whatever transformation is required
            X = self.X
            Y = self.Y
            Z = self.Z

            # reverse the Z's
            Z = list(Z); Z.reverse(); Z = array(Z)

            _pylab.imshow(Z, cmap=colormap,
                      extent=[X[0]-x_width/2.0, X[-1]+x_width/2.0,
                      Y[0]+y_width/2.0, Y[-1]-y_width/2.0], **kwargs)
            _pylab.colorbar()
            _pt.image_set_aspect(1.0)

        # set the title and labels
        self.title = self.path
        a = _pylab.gca()
        a.set_title(self.title)
        a.set_xlabel(self.xlabel)
        a.set_ylabel(self.ylabel)
Esempio n. 2
0
def image_data(Z, X=[0,1.0], Y=[0,1.0], aspect=1.0, zmin=None, zmax=None, clear=1, **kwargs):
    """
    Generates an image or 3d plot

    X                       1-d array of x-values
    Y                       1-d array of y-values
    Z                       2-d array of z-values

    X and Y can be something like [0,2] or an array of X-values
    """

    fig = _pylab.gcf()
    if clear: 
        fig.clear()
        _pylab.axes()

    # generate the 3d axes
    X = _numpy.array(X)
    Y = _numpy.array(Y)
    Z = _numpy.array(Z)

    # assume X and Y are the bin centers and figure out the bin widths
    x_width = abs(float(X[-1] - X[0])/(len(Z[0])-1))
    y_width = abs(float(Y[-1] - Y[0])/(len(Z)-1))
    
    # reverse the Z's
    Z = Z[-1::-1]
    
    # get rid of the label and title kwargs
    xlabel=''
    ylabel=''
    title =''
    if kwargs.has_key('xlabel'): xlabel = kwargs.pop('xlabel')
    if kwargs.has_key('ylabel'): ylabel = kwargs.pop('ylabel')
    if kwargs.has_key('title'):  title  = kwargs.pop('title')
    
    _pylab.imshow(Z, extent=[X[0]-x_width/2.0, X[-1]+x_width/2.0,
                             Y[0]-y_width/2.0, Y[-1]+y_width/2.0], **kwargs)    
    _pylab.colorbar()
    _pt.image_set_clim(zmin,zmax)
    _pt.image_set_aspect(aspect)
    
    a = _pylab.gca()
    a.set_title(title)
    a.set_xlabel(xlabel)
    a.set_ylabel(ylabel)
    
    _pt.close_sliders()
    _pt.image_sliders()

    _pt.raise_figure_window()
    _pt.raise_pyshell()
    _pylab.draw()
    
    return _pylab.gca()
Esempio n. 3
0
def image_data(Z,
               X=[0, 1.0],
               Y=[0, 1.0],
               aspect=1.0,
               zmin=None,
               zmax=None,
               clear=1,
               title='',
               clabel='z',
               autoformat=True,
               colormap="Last Used",
               shell_history=1,
               **kwargs):
    """
    Generates an image or 3d plot

    X                       1-d array of x-values
    Y                       1-d array of y-values
    Z                       2-d array of z-values

    X and Y can be something like [0,2] or an array of X-values

    kwargs are sent to pylab.imshow()
    """
    global _colormap

    _pylab.ioff()

    fig = _pylab.gcf()
    if clear:
        fig.clear()
        _pylab.axes()

    # generate the 3d axes
    X = _n.array(X)
    Y = _n.array(Y)
    Z = _n.array(Z)

    # assume X and Y are the bin centers and figure out the bin widths
    x_width = abs(float(X[-1] - X[0]) / (len(Z[0]) - 1))
    y_width = abs(float(Y[-1] - Y[0]) / (len(Z) - 1))

    # reverse the Z's
    Z = Z[-1::-1]

    # get rid of the label and title kwargs
    xlabel = ''
    ylabel = ''
    title = ''
    if kwargs.has_key('xlabel'): xlabel = kwargs.pop('xlabel')
    if kwargs.has_key('ylabel'): ylabel = kwargs.pop('ylabel')
    if kwargs.has_key('title'): title = kwargs.pop('title')

    _pylab.imshow(Z,
                  extent=[
                      X[0] - x_width / 2.0, X[-1] + x_width / 2.0,
                      Y[0] - y_width / 2.0, Y[-1] + y_width / 2.0
                  ],
                  **kwargs)
    cb = _pylab.colorbar()
    _pt.image_set_clim(zmin, zmax)
    _pt.image_set_aspect(aspect)
    cb.set_label(clabel)

    a = _pylab.gca()
    a.set_xlabel(xlabel)
    a.set_ylabel(ylabel)

    #_pt.close_sliders()
    #_pt.image_sliders()

    # title
    history = _fun.get_shell_history()
    for n in range(0, min(shell_history, len(history))):
        title = title + "\n" + history[n].split('\n')[0].strip()

    title = title + '\nPlot created ' + _time.asctime()
    a.set_title(title.strip())

    if autoformat: _pt.image_format_figure(fig)

    _pylab.ion()
    _pylab.show()
    #_pt.raise_figure_window()
    #_pt.raise_pyshell()
    _pylab.draw()

    # add the color sliders
    if colormap:
        if _colormap: _colormap.close()
        _colormap = _pt.image_colormap(colormap, image=a.images[0])
Esempio n. 4
0
def image_data(Z, X=[0,1.0], Y=[0,1.0], aspect=1.0, zmin=None, zmax=None, clear=1, clabel='z', autoformat=True, colormap="Last Used", shell_history=1, **kwargs):
    """
    Generates an image or 3d plot

    X                       1-d array of x-values
    Y                       1-d array of y-values
    Z                       2-d array of z-values

    X and Y can be something like [0,2] or an array of X-values

    kwargs are sent to pylab.imshow()
    """
    global _colormap

    _pylab.ioff()

    fig = _pylab.gcf()
    if clear:
        fig.clear()
        _pylab.axes()

    # generate the 3d axes
    X = _n.array(X)
    Y = _n.array(Y)
    Z = _n.array(Z)

    # assume X and Y are the bin centers and figure out the bin widths
    x_width = abs(float(X[-1] - X[0])/(len(Z[0])-1))
    y_width = abs(float(Y[-1] - Y[0])/(len(Z)-1))

    # reverse the Z's
    Z = Z[-1::-1]

    # get rid of the label and title kwargs
    xlabel=''
    ylabel=''
    title =''
    if kwargs.has_key('xlabel'): xlabel = kwargs.pop('xlabel')
    if kwargs.has_key('ylabel'): ylabel = kwargs.pop('ylabel')
    if kwargs.has_key('title'):  title  = kwargs.pop('title')

    _pylab.imshow(Z, extent=[X[0]-x_width/2.0, X[-1]+x_width/2.0,
                             Y[0]-y_width/2.0, Y[-1]+y_width/2.0], **kwargs)
    cb = _pylab.colorbar()
    _pt.image_set_clim(zmin,zmax)
    _pt.image_set_aspect(aspect)
    cb.set_label(clabel)

    a = _pylab.gca()
    a.set_xlabel(xlabel)
    a.set_ylabel(ylabel)

    #_pt.close_sliders()
    #_pt.image_sliders()

    # title
    history = _fun.get_shell_history()
    for n in range(0, min(shell_history, len(history))):
        title = title + "\n" + history[n].split('\n')[0].strip()

    title = title + '\nPlot created ' + _time.asctime()
    a.set_title(title.strip())

    if autoformat: _pt.image_format_figure(fig)

    _pylab.ion()
    _pylab.show()
    #_pt.raise_figure_window()
    #_pt.raise_pyshell()
    _pylab.draw()

    # add the color sliders
    if colormap:
        if _colormap: _colormap.close()
        _colormap = _pt.image_colormap(colormap, image=a.images[0])
Esempio n. 5
0
def image_data(Z, X=[0,1.0], Y=[0,1.0], aspect=1.0, zmin=None, zmax=None, clear=1, clabel='z', autoformat=True, colormap="Last Used", shell_history=0, **kwargs):
    """
    Generates an image plot.
    
    Parameters
    ----------
    Z   
        2-d array of z-values
    X=[0,1.0], Y=[0,1.0]
        1-d array of x-values (only the first and last element are used)
    
    See matplotlib's imshow() for additional optional arguments. 
    """
    global _colormap
    
    # Set interpolation to something more relevant for every day science
    if not 'interpolation' in kwargs.keys(): kwargs['interpolation'] = 'nearest'

    _pylab.ioff()

    fig = _pylab.gcf()
    if clear:
        fig.clear()
        _pylab.axes()

    # generate the 3d axes
    X = _n.array(X)
    Y = _n.array(Y)
    Z = _n.array(Z)

    # assume X and Y are the bin centers and figure out the bin widths
    x_width = abs(float(X[-1] - X[0])/(len(Z[0])-1))
    y_width = abs(float(Y[-1] - Y[0])/(len(Z)-1))

    # reverse the Z's
    # Transpose and reverse
    Z = Z.transpose()
    Z = Z[-1::-1]
    
    
    # get rid of the label and title kwargs
    xlabel=''
    ylabel=''
    title =''
    if 'xlabel' in kwargs: xlabel = kwargs.pop('xlabel')
    if 'ylabel' in kwargs: ylabel = kwargs.pop('ylabel')
    if 'title' in kwargs:  title  = kwargs.pop('title')

    _pylab.imshow(Z, extent=[X[0]-x_width/2.0, X[-1]+x_width/2.0,
                             Y[0]-y_width/2.0, Y[-1]+y_width/2.0], **kwargs)
    cb = _pylab.colorbar()
    _pt.image_set_clim(zmin,zmax)
    _pt.image_set_aspect(aspect)
    cb.set_label(clabel)

    a = _pylab.gca()
    a.set_xlabel(xlabel)
    a.set_ylabel(ylabel)

    #_pt.close_sliders()
    #_pt.image_sliders()

    # title
    history = _fun.get_shell_history()
    for n in range(0, min(shell_history, len(history))):
        title = title + "\n" + history[n].split('\n')[0].strip()

    title = title + '\nPlot created ' + _time.asctime()
    a.set_title(title.strip())

    if autoformat: _pt.image_format_figure(fig)

    _pylab.ion()
    _pylab.show()
    #_pt.raise_figure_window()
    #_pt.raise_pyshell()
    _pylab.draw()

    # add the color sliders
    if colormap:
        if _colormap: _colormap.close()
        _colormap = _pt.image_colormap(colormap, image=a.images[0])
Esempio n. 6
0
def image_data(Z, X=[0,1.0], Y=[0,1.0], aspect=1.0, zmin=None, zmax=None, clear=1, clabel='z', autoformat=True, colormap="Last Used", shell_history=0, **kwargs):
    """
    Generates an image plot.
    
    Parameters
    ----------
    Z   
        2-d array of z-values
    X=[0,1.0], Y=[0,1.0]
        1-d array of x-values (only the first and last element are used)
    
    See matplotlib's imshow() for additional optional arguments. 
    """
    global _colormap
    
    # Set interpolation to something more relevant for every day science
    if not 'interpolation' in kwargs.keys(): kwargs['interpolation'] = 'nearest'

    _pylab.ioff()

    fig = _pylab.gcf()
    if clear:
        fig.clear()
        _pylab.axes()

    # generate the 3d axes
    X = _n.array(X)
    Y = _n.array(Y)
    Z = _n.array(Z)

    # assume X and Y are the bin centers and figure out the bin widths
    x_width = abs(float(X[-1] - X[0])/(len(Z[0])-1))
    y_width = abs(float(Y[-1] - Y[0])/(len(Z)-1))

    # reverse the Z's
    # Transpose and reverse
    Z = Z.transpose()
    Z = Z[-1::-1]
    
    
    # get rid of the label and title kwargs
    xlabel=''
    ylabel=''
    title =''
    if 'xlabel' in kwargs: xlabel = kwargs.pop('xlabel')
    if 'ylabel' in kwargs: ylabel = kwargs.pop('ylabel')
    if 'title' in kwargs:  title  = kwargs.pop('title')

    _pylab.imshow(Z, extent=[X[0]-x_width/2.0, X[-1]+x_width/2.0,
                             Y[0]-y_width/2.0, Y[-1]+y_width/2.0], **kwargs)
    cb = _pylab.colorbar()
    _pt.image_set_clim(zmin,zmax)
    _pt.image_set_aspect(aspect)
    cb.set_label(clabel)

    a = _pylab.gca()
    a.set_xlabel(xlabel)
    a.set_ylabel(ylabel)

    #_pt.close_sliders()
    #_pt.image_sliders()

    # title
    history = _fun.get_shell_history()
    for n in range(0, min(shell_history, len(history))):
        title = title + "\n" + history[n].split('\n')[0].strip()

    title = title + '\nPlot created ' + _time.asctime()
    a.set_title(title.strip())

    if autoformat: _pt.image_format_figure(fig)

    _pylab.ion()
    _pylab.show()
    #_pt.raise_figure_window()
    #_pt.raise_pyshell()
    _pylab.draw()

    # add the color sliders
    if colormap:
        if _colormap: _colormap.close()
        _colormap = _pt.image_colormap(colormap, image=a.images[0])
Esempio n. 7
0
def image_data(Z,
               X=[0, 1.0],
               Y=[0, 1.0],
               aspect=1.0,
               zmin=None,
               zmax=None,
               clear=1,
               **kwargs):
    """
    Generates an image or 3d plot

    X                       1-d array of x-values
    Y                       1-d array of y-values
    Z                       2-d array of z-values

    X and Y can be something like [0,2] or an array of X-values
    """

    fig = _pylab.gcf()
    if clear:
        fig.clear()
        _pylab.axes()

    # generate the 3d axes
    X = _numpy.array(X)
    Y = _numpy.array(Y)
    Z = _numpy.array(Z)

    # assume X and Y are the bin centers and figure out the bin widths
    x_width = abs(float(X[-1] - X[0]) / (len(Z[0]) - 1))
    y_width = abs(float(Y[-1] - Y[0]) / (len(Z) - 1))

    # reverse the Z's
    Z = Z[-1::-1]

    # get rid of the label and title kwargs
    xlabel = ''
    ylabel = ''
    title = ''
    if kwargs.has_key('xlabel'): xlabel = kwargs.pop('xlabel')
    if kwargs.has_key('ylabel'): ylabel = kwargs.pop('ylabel')
    if kwargs.has_key('title'): title = kwargs.pop('title')

    _pylab.imshow(Z,
                  extent=[
                      X[0] - x_width / 2.0, X[-1] + x_width / 2.0,
                      Y[0] - y_width / 2.0, Y[-1] + y_width / 2.0
                  ],
                  **kwargs)
    _pylab.colorbar()
    _pt.image_set_clim(zmin, zmax)
    _pt.image_set_aspect(aspect)

    a = _pylab.gca()
    a.set_title(title)
    a.set_xlabel(xlabel)
    a.set_ylabel(ylabel)

    _pt.close_sliders()
    _pt.image_sliders()

    _pt.raise_figure_window()
    _pt.raise_pyshell()
    _pylab.draw()

    return _pylab.gca()
Esempio n. 8
0
    def plot_XYZ(self, cmap="Blues", plot="image", **kwargs):
        """
        This is 8 million times faster than pseudocolor I guess, but it won't handle unevenly spaced stuff.

        You need to generate X, Y and Z first, probably using get_XYZ.

        cmap    Name of the matplotlib cmap to use
        plot    Type of plot, "image" for fast colorplot, "mountains" for slow 3d plot
        """

        # if we don't have the data, tell the user
        if self.X == None or self.Y == None or self.Z == None:
            print "You haven't assembled the surface data yet. Use get_XYZ first!"
            return

        # try the user's colormap
        try:
            colormap = eval("_pylab.cm." + cmap)
        except:
            print "ERROR: Invalid colormap, using default."
            colormap = _pylab.cm.Blues

        # at this point we have X, Y, Z and a colormap, so plot the mf.
        f = _pylab.gcf()
        f.clear()

        if plot.lower() == "mountains":
            X, Y = meshgrid(self.X, self.Y)
            a = Axes3D(f)
            a.plot_surface(X,
                           Y,
                           self.Z,
                           rstride=2,
                           cstride=2,
                           cmap=colormap,
                           **kwargs)

        else:
            # assume X and Y are the bin centers and figure out the bin widths
            x_width = abs(float(self.X[-1] - self.X[0]) / (len(self.X) - 1))
            y_width = abs(float(self.Y[-1] - self.Y[0]) / (len(self.Y) - 1))

            # do whatever transformation is required
            X = self.X
            Y = self.Y
            Z = self.Z

            # reverse the Z's
            Z = list(Z)
            Z.reverse()
            Z = array(Z)

            _pylab.imshow(Z,
                          cmap=colormap,
                          extent=[
                              X[0] - x_width / 2.0, X[-1] + x_width / 2.0,
                              Y[0] + y_width / 2.0, Y[-1] - y_width / 2.0
                          ],
                          **kwargs)
            _pylab.colorbar()
            _pt.image_set_aspect(1.0)

        # set the title and labels
        self.title = self.path
        a = _pylab.gca()
        a.set_title(self.title)
        a.set_xlabel(self.xlabel)
        a.set_ylabel(self.ylabel)