def __init__(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x = x, y = y)
        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")
        # Create the line plot
        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")
        # Create a horizontal container and put the two plots inside it
        container = HPlotContainer(scatter, line)
        container.spacing = 0
        scatter.padding_right = 0
        line.padding_left = 0
        line.y_axis.orientation = "right"

        self.plot = container
Beispiel #2
0
def _create_plot_component(file_name):
    # Create a scalar field to colormap
    z = load(file_name)
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)
    
    # Create the plot
    plot = Plot(pd)
    plot.bgcolor = 'gray'
    
    img_plot = plot.img_plot("imagedata",
                             name='my_plot', 
                             colormap=jet,
                             hide_grids=True)[0]
    #cont_plot=plot.contour_plot('imagedata', type='line', name='countour')
    # Tweak some of the plot properties
    #plot.title = file_name
    plot.padding = 40
    plot.padding_right=20
    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    #plot.tools.append(TraitsTool(plot))
    zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False)
    img_plot.overlays.append(zoom)
    #plot.y_axis.tick_label_formatter = lambda x: "%.3e" % x
    #plot.x_axis.tick_label_formatter = lambda x: "%.3e" % x
    #plot.tools.append(SaveTool(plot))
    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    my_plot = img_plot#plot.plots["my_plot"][0]
    colormap = my_plot.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=my_plot,
                        orientation='v',
                        resizable='v',
                        width=25,
                        padding=0)
    colorbar.origin = 'bottom left'
    #colorbar._axis.tick_label_formatter = lambda x: '%.0e'%(x*10e6) + u' [\u00b5' + 'Watt]'
    colorbar._axis.tick_label_formatter = lambda x: ('%.0e'%(x*1e6))
    colorbar._axis.orientation = 'right'
    colorbar._axis.title = u'Intensity [\u00b5W]'
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom
    colorbar.padding_right = 100
    # create a range selection for the colorbar
    range_selection = RangeSelection(component=colorbar)
    colorbar.tools.append(range_selection)
    colorbar.overlays.append(RangeSelectionOverlay(component=colorbar,
                                                   border_color="white",
                                                   alpha=0.5,
                                                   fill_color="lightgray"))
    
    range_selection.listeners.append(my_plot)
    
    imgtool = ImageInspectorTool(img_plot)
    img_plot.tools.append(imgtool)
    plot.overlays.append(ImageInspectorOverlay(component=img_plot, image_inspector=imgtool))
    # we also want to the range selection to inform the cmap plot of
    # the selection, so set that up as well

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(use_backbuffer = True)
    container.add(plot)
    container.add(colorbar)
    container.bgcolor = "white"
    container.tools.append(SaveTool(container))
    container.tools.append(TraitsTool(container))
    #my_plot.set_value_selection((-1.3, 6.9))
    return container