Example #1
0
def _create_plot_component():

    # Create a scalar field to contour
    # uses a randomly sampled, non-uniform grid
    xs = uniform(-2*pi, 2*pi, 600)
    xs.sort()
    ys = uniform(-1.5*pi, 1.5*pi, 300)
    ys.sort()
    x, y = meshgrid(xs,ys)
    z = tanh(x*y/6)*cosh(exp(-y**2)*x/3)
    z = x*y

    # mask out a region with nan values
    mask = ((abs(x-5) <= 1) & (abs(y-2) <= 2))
    z[mask] = nan

    # Create a plot data object and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create a contour polygon plot of the data
    plot = Plot(pd, default_origin="bottom left")
    plot.contour_plot("imagedata",
                      type="poly",
                      poly_cmap=jet,
                      xbounds=x,
                      ybounds=y)

    # Create a contour line plot for the data, too
    plot.contour_plot("imagedata",
                      type="line",
                      xbounds=x,
                      ybounds=y)

    # Tweak some of the plot properties
    plot.title = "My First Contour Plot"
    plot.padding = 50
    plot.bg_color = "white"
    plot.fill_padding = True

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)
    return plot
Example #2
0
def test_bounds_2d_case():
    # test for bug: contour and image plots should support the case where
    # xbounds and ybounds are 2d arrays resulting from meshgrids

    xs = np.linspace(-10,10,200)
    ys = np.linspace(-10,10,400)
    x, y = np.meshgrid(xs,ys)
    z = x + y

    plotdata = ArrayPlotData()
    plotdata.set_data("z", z)

    plot = Plot(plotdata)
    plot.contour_plot("z", xbounds=x, ybounds=y)

    # try to display it, that's when the exception is raised
    with store_exceptions_on_all_threads():
        pv = PlotViewer(plot=plot)
        pv.edit_traits()
Example #3
0
def test_bounds_2d_case():
    # test for bug: contour and image plots should support the case where
    # xbounds and ybounds are 2d arrays resulting from meshgrids

    xs = np.linspace(-10, 10, 200)
    ys = np.linspace(-10, 10, 400)
    x, y = np.meshgrid(xs, ys)
    z = x + y

    plotdata = ArrayPlotData()
    plotdata.set_data("z", z)

    plot = Plot(plotdata)
    plot.contour_plot("z", xbounds=x, ybounds=y)

    # try to display it, that's when the exception is raised
    with store_exceptions_on_all_threads():
        pv = PlotViewer(plot=plot)
        pv.edit_traits()
def _create_plot_component():

    # Create a scalar field to contour
    # uses a randomly sampled, non-uniform grid
    xs = uniform(-2 * pi, 2 * pi, 600)
    xs.sort()
    ys = uniform(-1.5 * pi, 1.5 * pi, 300)
    ys.sort()
    x, y = meshgrid(xs, ys)
    z = tanh(x * y / 6) * cosh(exp(-y**2) * x / 3)
    z = x * y

    # mask out a region with nan values
    mask = ((abs(x - 5) <= 1) & (abs(y - 2) <= 2))
    z[mask] = nan

    # Create a plot data object and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create a contour polygon plot of the data
    plot = Plot(pd, default_origin="bottom left")
    plot.contour_plot("imagedata",
                      type="poly",
                      poly_cmap=jet,
                      xbounds=x,
                      ybounds=y)

    # Create a contour line plot for the data, too
    plot.contour_plot("imagedata", type="line", xbounds=x, ybounds=y)

    # Tweak some of the plot properties
    plot.title = "My First Contour Plot"
    plot.padding = 50
    plot.bg_color = "white"
    plot.fill_padding = True

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)
    return plot
Example #5
0
    def contour_plot_from_data(self, anim_data, array_names, style_dict=None):
        """ Returns the Container of contour plot corresponding to the
        array data in anim_data w.r.t. arraynames

        Parameters
        ----------
        anim_data: AnimationData
            Animation data to plot as a contour plot.

        array_names: 4-tuple of strings
            Attr names in anim_data which will be (x,y,z, levels) arrays for
            the contour plot.

        style_dict: dict
            Dictionary of extra stylings to set, currently allowing up to one
            level of nesting of attributes (with '' key meaning no nesting).
        """
        plot = Plot(self.plot_data)
        x_name, y_name, z_name, levels_name = array_names
        xs = getattr(anim_data, x_name)
        xbounds = (min(xs), max(xs))
        ys = getattr(anim_data, y_name)
        ybounds = (min(ys), max(ys))
        levels = getattr(anim_data, levels_name).tolist()
        kwargs = style_dict.get('') if '' in style_dict else {}

        # Override the colormap's range with the full range of the data
        if style_dict is BOUND_CONC_PLOT_STYLE_DICT:
            data_max = self.active_anim_data.beadboundZ.max()
        else:
            data_max = self.active_anim_data.columnliqZ.max()

        contour_plot = plot.contour_plot(z_name,
                                         xbounds=xbounds,
                                         ybounds=ybounds,
                                         levels=levels,
                                         **kwargs)[0]

        # Overwrite the colormapper range to be set by the full data, not just
        # the 1 time slice currently plotted:
        contour_plot.color_mapper.range.set_bounds(EPS, data_max)
        contour_plot.color_mapper.updated = True

        # Adjust plot style for any remaining attrs
        for attr_name, attr_styles in style_dict.items():
            if attr_name == '':
                continue
            attr = getattr(plot, attr_name)
            for attr_attr_name, attr_attr_val in attr_styles.items():
                setattr(attr, attr_attr_name, attr_attr_val)

        return plot
Example #6
0
def _create_plot_component():

    # Create a scalar field to contour
    xs = linspace(-2 * pi, 2 * pi, 600)
    ys = linspace(-1.5 * pi, 1.5 * pi, 300)
    x, y = meshgrid(xs, ys)
    z = tanh(x * y / 6) * cosh(exp(-y**2) * x / 3)
    z = x * y

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create a contour polygon plot of the data
    plot = Plot(pd, default_origin="top left")
    plot.contour_plot("imagedata",
                      type="poly",
                      poly_cmap=jet,
                      xbounds=(xs[0], xs[-1]),
                      ybounds=(ys[0], ys[-1]))

    # Create a contour line plot for the data, too
    plot.contour_plot("imagedata",
                      type="line",
                      xbounds=(xs[0], xs[-1]),
                      ybounds=(ys[0], ys[-1]))

    # Tweak some of the plot properties
    plot.title = "My First Contour Plot"
    plot.padding = 50
    plot.bg_color = "white"
    plot.fill_padding = True

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)
    return plot
Example #7
0
def _create_plot_component():

    # Create img data to colormap
    fname = "/Users/maye/Data/hirise/PSP_003092_0985/PSP_003092_0985_RED.cal.norm.map.equ.mos.cub"
    hirise = mars.HiRISE(fname)
    win1 = mars.Window(mars.Point(1792*2,5888*2),width=512)
    hirise.read_window(win1)
    hirise.normalize()

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", hirise.data)

    # Create the left plot, a colormap and simple contours
    lplot = Plot(pd)
    lplot.img_plot("imagedata",
                   name="cm_plot",
                   # xbounds=x_extents,
                   # ybounds=y_extents,
                   origin='top left',
                   colormap=gmt_drywet)
    # lplot.contour_plot("imagedata",
    #                    type="line",
    #                    # xbounds=x_extents,
    #                    # ybounds=y_extents,
    #                    )

    # Tweak some of the plot properties
    lplot.title = "Colormap and contours"
    lplot.padding = 20
    lplot.bg_color = "white"
    lplot.fill_padding = True

    # Add some tools to the plot
    zoom = ZoomTool(lplot, tool_mode="box", always_on=False)
    lplot.overlays.append(zoom)
    lplot.tools.append(PanTool(lplot, constrain_key="shift"))

    # # Right now, some of the tools are a little invasive, and we need the
    # # actual CMapImage object to give to them
    # cm_plot = lplot.plots["cm_plot"][0]
    # 
    # # Create the colorbar, handing in the appropriate range and colormap
    # colormap = cm_plot.color_mapper
    # colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
    #                     color_mapper=colormap,
    #                     plot=cm_plot,
    #                     orientation='v',
    #                     resizable='v',
    #                     width=30,
    #                     padding=20)
    # colorbar.padding_top = lplot.padding_top
    # colorbar.padding_bottom = lplot.padding_bottom

    # Create the left plot, contours of varying color and width
    rplot = Plot(pd, range2d=lplot.range2d)
    rplot.contour_plot("imagedata",
                       type="line",
                       # xbounds=x_extents,
                       # ybounds=y_extents,
                       bgcolor="black",
                       levels=15,
                       styles="solid",
                       widths=list(linspace(4.0, 0.1, 15)),
                       colors=gmt_drywet)

    # Add some tools to the plot
    zoom = ZoomTool(rplot, tool_mode="box", always_on=False)
    rplot.overlays.append(zoom)
    rplot.tools.append(PanTool(rplot, constrain_key="shift"))

    # Tweak some of the plot properties
    rplot.title = "Varying contour lines"
    rplot.padding = 20
    rplot.bg_color = "white"
    rplot.fill_padding = True

    # Create a container and add our plots
    container = HPlotContainer(padding=40, fill_padding=True,
                               bgcolor = "white", use_backbuffer=True)
    container.add(colorbar)
    container.add(lplot)
    container.add(rplot)
    return container
Example #8
0
def _create_plot_component():

    # Create a scalar field to colormap
    x_extents = (-2 * pi, 2 * pi)
    y_extents = (-1.5 * pi, 1.5 * pi)
    xs = linspace(-2 * pi, 2 * pi, 200)
    ys = linspace(-1.5 * pi, 1.5 * pi, 100)
    x, y = meshgrid(xs, ys)
    zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \
            sin(((x+1)**2 + y**2)/4)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", zs)

    # Create the left plot, a colormap and simple contours
    lplot = Plot(pd)
    lplot.img_plot("imagedata",
                   name="cm_plot",
                   xbounds=x_extents,
                   ybounds=y_extents,
                   colormap=gmt_drywet)
    lplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents)

    # Tweak some of the plot properties
    lplot.title = "Colormap and contours"
    lplot.padding = 20
    lplot.bg_color = "white"
    lplot.fill_padding = True

    # Add some tools to the plot
    zoom = ZoomTool(lplot, tool_mode="box", always_on=False)
    lplot.overlays.append(zoom)
    lplot.tools.append(PanTool(lplot, constrain_key="shift"))

    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    cm_plot = lplot.plots["cm_plot"][0]

    # Create the colorbar, handing in the appropriate range and colormap
    colormap = cm_plot.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=cm_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)
    colorbar.padding_top = lplot.padding_top
    colorbar.padding_bottom = lplot.padding_bottom

    # Create the left plot, contours of varying color and width
    rplot = Plot(pd, range2d=lplot.range2d)
    rplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents,
                       bgcolor="black",
                       levels=15,
                       styles="solid",
                       widths=list(linspace(4.0, 0.1, 15)),
                       colors=gmt_drywet)

    # Add some tools to the plot
    zoom = ZoomTool(rplot, tool_mode="box", always_on=False)
    rplot.overlays.append(zoom)
    rplot.tools.append(PanTool(rplot, constrain_key="shift"))

    # Tweak some of the plot properties
    rplot.title = "Varying contour lines"
    rplot.padding = 20
    rplot.bg_color = "white"
    rplot.fill_padding = True

    # Create a container and add our plots
    container = HPlotContainer(padding=40,
                               fill_padding=True,
                               bgcolor="white",
                               use_backbuffer=True)
    container.add(colorbar)
    container.add(lplot)
    container.add(rplot)
    return container
Example #9
0
def _create_plot_component():

    # Create a scalar field to colormap
    x_extents = (-2*pi, 2*pi)
    y_extents = (-1.5*pi, 1.5*pi)
    xs = linspace(-2*pi, 2*pi, 200)
    ys = linspace(-1.5*pi, 1.5*pi, 100)
    x, y = meshgrid(xs,ys)
    zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \
            sin(((x+1)**2 + y**2)/4)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", zs)

    # Create the left plot, a colormap and simple contours
    lplot = Plot(pd)
    lplot.img_plot("imagedata",
                   name="cm_plot",
                   xbounds=x_extents,
                   ybounds=y_extents,
                   colormap=gmt_drywet)
    lplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents)

    # Tweak some of the plot properties
    lplot.title = "Colormap and contours"
    lplot.padding = 20
    lplot.bg_color = "white"
    lplot.fill_padding = True

    # Add some tools to the plot
    zoom = ZoomTool(lplot, tool_mode="box", always_on=False)
    lplot.overlays.append(zoom)
    lplot.tools.append(PanTool(lplot, constrain_key="shift"))

    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    cm_plot = lplot.plots["cm_plot"][0]

    # Create the colorbar, handing in the appropriate range and colormap
    colormap = cm_plot.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=cm_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)
    colorbar.padding_top = lplot.padding_top
    colorbar.padding_bottom = lplot.padding_bottom

    # Create the left plot, contours of varying color and width
    rplot = Plot(pd, range2d=lplot.range2d)
    rplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents,
                       bgcolor="black",
                       levels=15,
                       styles="solid",
                       widths=list(linspace(4.0, 0.1, 15)),
                       colors=gmt_drywet)

    # Add some tools to the plot
    zoom = ZoomTool(rplot, tool_mode="box", always_on=False)
    rplot.overlays.append(zoom)
    rplot.tools.append(PanTool(rplot, constrain_key="shift"))

    # Tweak some of the plot properties
    rplot.title = "Varying contour lines"
    rplot.padding = 20
    rplot.bg_color = "white"
    rplot.fill_padding = True

    # Create a container and add our plots
    container = HPlotContainer(padding=40, fill_padding=True,
                               bgcolor = "white", use_backbuffer=True)
    container.add(colorbar)
    container.add(lplot)
    container.add(rplot)
    return container
 def __init__(self, *args, **kwargs):
     super(Demo, self).__init__(*args, **kwargs)
     
     from imread import imread
     imarray = imread(find_resource('imageAlignment', '../images/GIRLS-IN-SPACE.jpg',
         '../images/GIRLS-IN-SPACE.jpg', return_path=True))
     
     self.pd = ArrayPlotData(imagedata=imarray)
     #self.pd.x_axis.orientation = "top"
     self.plot = HPlotContainer()
     
     titles = ["I KEEP DANCE", "ING ON MY OWN"]
     
     
     self._load()
     
     i = 0
     for plc in [Plot, Plot]:
         xs = linspace(0, 334*pi, 333)
         ys = linspace(0, 334*pi, 333)
         x, y = meshgrid(xs,ys)
         z = tanh(x*y/6)*cosh(exp(-y**2)*x/3)
         z = x*y
         
         _pd = ArrayPlotData()
         _pd.set_data("drawdata", z)
         _pd.set_data("imagedata", self.pd.get_data('imagedata'))
         
         plc = Plot(_pd,
             title="render_style = hold",
             padding=50, border_visible=True, overlay_border=True)
         
         self.plot.add(plc)
         
         plc.img_plot("imagedata",
             alpha=0.95)
         
         # Create a contour polygon plot of the data
         plc.contour_plot("drawdata",
                           type="poly",
                           poly_cmap=jet,
                           xbounds=(0, 499),
                           ybounds=(0, 582),
                           alpha=0.35)
         
         # Create a contour line plot for the data, too
         plc.contour_plot("drawdata",
                           type="line",
                           xbounds=(0, 499),
                           ybounds=(0, 582),
                           alpha=0.35)
         
         # Create a plot data obect and give it this data
         plc.legend.visible = True
         plc.title = titles[i]
         i += 1
         
         #plc.plot(("index", "y0"), name="j_0", color="red", render_style="hold")
         
         #plc.padding = 50
         #plc.padding_top = 75
         plc.tools.append(PanTool(plc))
         zoom = ZoomTool(component=plc, tool_mode="box", always_on=False)
         plc.overlays.append(zoom)
         
         # Tweak some of the plot properties
         plc.padding = 50
         #zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False)
         #plot1.overlays.append(zoom)
         
         # Attach some tools to the plot
         #attach_tools(plc)
         plc.bg_color = None
         plc.fill_padding = True