本文整理汇总了Python中chaco.api.HPlotContainer类的典型用法代码示例。如果您正苦于以下问题:Python HPlotContainer类的具体用法?Python HPlotContainer怎么用?Python HPlotContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HPlotContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
# The delegates views don't work unless we caller the superclass __init__
super(CursorTest, self).__init__()
container = HPlotContainer(padding=0, spacing=20)
self.plot = container
# a subcontainer for the first plot.
# I'm not sure why this is required. Without it, the layout doesn't work right.
subcontainer = OverlayPlotContainer(padding=40)
container.add(subcontainer)
# make some data
index = numpy.linspace(-10, 10, 512)
value = numpy.sin(index)
# create a LinePlot instance and add it to the subcontainer
line = create_line_plot([index, value], add_grid=True, add_axis=True, index_sort="ascending", orientation="h")
subcontainer.add(line)
# here's our first cursor.
csr = CursorTool(line, drag_button="left", color="blue")
self.cursor1 = csr
# and set it's initial position (in data-space units)
csr.current_position = 0.0, 0.0
# this is a rendered component so it goes in the overlays list
line.overlays.append(csr)
# some other standard tools
line.tools.append(PanTool(line, drag_button="right"))
line.overlays.append(ZoomTool(line))
# make some 2D data for a colourmap plot
xy_range = (-5, 5)
x = numpy.linspace(xy_range[0], xy_range[1], 100)
y = numpy.linspace(xy_range[0], xy_range[1], 100)
X, Y = numpy.meshgrid(x, y)
Z = numpy.sin(X) * numpy.arctan2(Y, X)
# easiest way to get a CMapImagePlot is to use the Plot class
ds = ArrayPlotData()
ds.set_data("img", Z)
img = Plot(ds, padding=40)
cmapImgPlot = img.img_plot("img", xbounds=xy_range, ybounds=xy_range, colormap=jet)[0]
container.add(img)
# now make another cursor
csr2 = CursorTool(cmapImgPlot, drag_button="left", color="white", line_width=2.0)
self.cursor2 = csr2
csr2.current_position = 1.0, 1.5
cmapImgPlot.overlays.append(csr2)
# add some standard tools. Note, I'm assigning the PanTool to the
# right mouse-button to avoid conflicting with the cursors
cmapImgPlot.tools.append(PanTool(cmapImgPlot, drag_button="right"))
cmapImgPlot.overlays.append(ZoomTool(cmapImgPlot))
示例2: control
def control(self):
"""
A drawable control with a color bar.
"""
color_map = self.plot_obj.color_mapper
linear_mapper = LinearMapper(range=color_map.range)
color_bar = ColorBar(index_mapper=linear_mapper, color_mapper=color_map, plot=self.plot_obj,
orientation='v', resizable='v', width=30)
color_bar._axis.tick_label_formatter = self.sci_formatter
color_bar.padding_top = self.padding_top
color_bar.padding_bottom = self.padding_bottom
color_bar.padding_left = 50 # Room for labels.
color_bar.padding_right = 10
range_selection = RangeSelection(component=color_bar)
range_selection.listeners.append(self.plot_obj)
color_bar.tools.append(range_selection)
range_selection_overlay = RangeSelectionOverlay(component=color_bar)
color_bar.overlays.append(range_selection_overlay)
container = HPlotContainer(use_backbuffer=True)
container.add(self)
container.add(color_bar)
return Window(self.parent, component=container).control
示例3: _container_default
def _container_default(self):
x = arange(-5.0, 15.0, 20.0/100)
y = jn(0, x)
left_plot = create_line_plot((x, y), bgcolor="white",
add_grid=True, add_axis=True)
left_plot.tools.append(PanTool(left_plot))
self.left_plot = left_plot
y = jn(1, x)
right_plot = create_line_plot((x, y), bgcolor="white",
add_grid=True, add_axis=True)
right_plot.tools.append(PanTool(right_plot))
right_plot.y_axis.orientation = "right"
self.right_plot = right_plot
# Tone down the colors on the grids
right_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5)
right_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5)
left_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5)
left_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5)
container = HPlotContainer(spacing=20, padding=50, bgcolor="lightgray")
container.add(left_plot)
container.add(right_plot)
return container
示例4: _create_plot_component
def _create_plot_component(self):
selected = Event()
# Create some x-y data series to plot
x = linspace(-2.0, 10.0, 100)
pd = ArrayPlotData(index = x)
for i in range(5):
pd.set_data("y" + str(i), jn(i,x))
# Create some line plots of some of the data
plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True)
plot1.legend.visible = True
plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
# Attach some tools to the plot
plot1.tools.append(PanTool(plot1))
self.zoom = BetterSelectingZoom(component=plot1, tool_mode="box", always_on=False, selection_completed = selected)
plot1.overlays.append(self.zoom)
container = HPlotContainer()
container.add(plot1)
self.zoom.on_trait_change(self.selection_changed, 'ratio')
return container
示例5: _create_plot_component
def _create_plot_component():
# Create some x-y data series to plot
x = linspace(-2.0, 10.0, 100)
pd = ArrayPlotData(index = x)
for i in range(5):
pd.set_data("y" + str(i), jn(i,x))
# Create some line plots of some of the data
plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True)
plot1.legend.visible = True
plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
plot1.plot(("index", "y3"), name="j_3", color="blue")
# Attach some tools to the plot
plot1.tools.append(PanTool(plot1))
zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False)
plot1.overlays.append(zoom)
# Create a second scatter plot of one of the datasets, linking its
# range to the first plot
plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=50,
border_visible=True)
plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle")
# Create a container and add our plots
container = HPlotContainer()
container.add(plot1)
container.add(plot2)
return container
示例6: _create_plot_component
def _create_plot_component():
# Create some x-y data series to plot
x = linspace(-2.0, 10.0, 40)
pd = ArrayPlotData(index = x, y0=jn(0,x))
# Create some line plots of some of the data
plot1 = Plot(pd, title="render_style = hold", padding=50, border_visible=True,
overlay_border = True)
plot1.legend.visible = True
lineplot = plot1.plot(("index", "y0"), name="j_0", color="red", render_style="hold")
# Attach some tools to the plot
attach_tools(plot1)
# Create a second scatter plot of one of the datasets, linking its
# range to the first plot
plot2 = Plot(pd, range2d=plot1.range2d, title="render_style = connectedhold",
padding=50, border_visible=True, overlay_border=True)
plot2.plot(('index', 'y0'), color="blue", render_style="connectedhold")
attach_tools(plot2)
# Create a container and add our plots
container = HPlotContainer()
container.add(plot1)
container.add(plot2)
return container
示例7: _create_plot_component
def _create_plot_component(obj):
# Setup the spectrum plot
frequencies = linspace(0.0, float(SAMPLING_RATE)/2, num=NUM_SAMPLES/2)
obj.spectrum_data = ArrayPlotData(frequency=frequencies)
empty_amplitude = zeros(NUM_SAMPLES/2)
obj.spectrum_data.set_data('amplitude', empty_amplitude)
obj.spectrum_plot = Plot(obj.spectrum_data)
spec_renderer = obj.spectrum_plot.plot(("frequency", "amplitude"), name="Spectrum",
color="red")[0]
obj.spectrum_plot.padding = 50
obj.spectrum_plot.title = "Spectrum"
spec_range = list(obj.spectrum_plot.plots.values())[0][0].value_mapper.range
spec_range.low = 0.0
spec_range.high = 5.0
obj.spectrum_plot.index_axis.title = 'Frequency (hz)'
obj.spectrum_plot.value_axis.title = 'Amplitude'
# Time Series plot
times = linspace(0.0, float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES)
obj.time_data = ArrayPlotData(time=times)
empty_amplitude = zeros(NUM_SAMPLES)
obj.time_data.set_data('amplitude', empty_amplitude)
obj.time_plot = Plot(obj.time_data)
obj.time_plot.plot(("time", "amplitude"), name="Time", color="blue")
obj.time_plot.padding = 50
obj.time_plot.title = "Time"
obj.time_plot.index_axis.title = 'Time (seconds)'
obj.time_plot.value_axis.title = 'Amplitude'
time_range = list(obj.time_plot.plots.values())[0][0].value_mapper.range
time_range.low = -0.2
time_range.high = 0.2
# Spectrogram plot
values = [zeros(NUM_SAMPLES/2) for i in range(SPECTROGRAM_LENGTH)]
p = WaterfallRenderer(index = spec_renderer.index, values = values,
index_mapper = LinearMapper(range = obj.spectrum_plot.index_mapper.range),
value_mapper = LinearMapper(range = DataRange1D(low=0, high=SPECTROGRAM_LENGTH)),
y2_mapper = LinearMapper(low_pos=0, high_pos=8,
range=DataRange1D(low=0, high=15)),
)
spectrogram_plot = p
obj.spectrogram_plot = p
dummy = Plot()
dummy.padding = 50
dummy.index_axis.mapper.range = p.index_mapper.range
dummy.index_axis.title = "Frequency (hz)"
dummy.add(p)
container = HPlotContainer()
container.add(obj.spectrum_plot)
container.add(obj.time_plot)
c2 = VPlotContainer()
c2.add(dummy)
c2.add(container)
return c2
示例8: _create_plot_component
def _create_plot_component():
# Create some x-y data series to plot
plot_area = OverlayPlotContainer(border_visible=True)
container = HPlotContainer(padding=50, bgcolor="transparent")
#container.spacing = 15
x = linspace(-2.0, 10.0, 100)
for i in range(5):
color = tuple(COLOR_PALETTE[i])
y = jn(i, x)
renderer = create_line_plot((x, y), color=color)
plot_area.add(renderer)
#plot_area.padding_left = 20
axis = PlotAxis(orientation="left", resizable="v",
mapper = renderer.y_mapper,
axis_line_color=color,
tick_color=color,
tick_label_color=color,
title_color=color,
bgcolor="transparent",
title = "jn_%d" % i,
border_visible = True,)
axis.bounds = [60,0]
axis.padding_left = 10
axis.padding_right = 10
container.add(axis)
if i == 4:
# Use the last plot's X mapper to create an X axis and a
# vertical grid
x_axis = PlotAxis(orientation="bottom", component=renderer,
mapper=renderer.x_mapper)
renderer.overlays.append(x_axis)
grid = PlotGrid(mapper=renderer.x_mapper, orientation="vertical",
line_color="lightgray", line_style="dot")
renderer.underlays.append(grid)
# Add the plot_area to the horizontal container
container.add(plot_area)
# Attach some tools to the plot
broadcaster = BroadcasterTool()
for plot in plot_area.components:
broadcaster.tools.append(PanTool(plot))
# Attach the broadcaster to one of the plots. The choice of which
# plot doesn't really matter, as long as one of them has a reference
# to the tool and will hand events to it.
plot.tools.append(broadcaster)
return container
示例9: Graph
class Graph(HasTraits):
plot=None
traits_view=View(Item('plot',editor=ComponentEditor(bgcolor="white"), show_label=False),
width=1200, height=1024, resizable=True, title="BacLog")
def __init__(self):
super(Graph,self).__init__()
self.container = HPlotContainer(padding=20, bgcolor="transparent")
self.plot_area = OverlayPlotContainer(border_visible=True)
def add(self,series,limit=None):
broadcaster = BroadcasterTool()
for name,line in series._plot.line.items():
if limit is not None and name not in limit:
continue
if line.time==[]:
print "Graph.add> empty:", name
continue
plot=create_line_plot((seconds(line.time),line.data),color=line.color)
self.plot_area.add(plot)
axis = PlotAxis(orientation="left", resizable="v",
mapper = plot.y_mapper,
bgcolor="white",
title = name,
title_color = line.color,
title_spacing = -4.0,
border_visible = True,)
## Visual style
axis.bounds = [60,0]
axis.padding_left = 1
axis.padding_right = 1
self.container.add(axis)
## Tools (attach to all for now)
plot.tools.append(broadcaster)
broadcaster.tools.append(PanTool(plot))
broadcaster.tools.append(DragZoom(plot,maintain_aspect_ratio=False,drag_button='right',restrict_domain=True))
def run(self):
## Time axis (first one)
plot=self.plot_area.components[0]
time = PlotAxis(orientation="bottom", component=plot, mapper=plot.x_mapper)
plot.overlays.append(time)
## Plot
self.container.add(self.plot_area)
self.plot=self.container
self.configure_traits()
示例10: _plot_default
def _plot_default(self):
data = self.data < self.limit
pd = self.pd = ArrayPlotData(imagedata=data,orig=self.data)
plot1 = Plot(pd, default_origin='top left')
plot2 = Plot(pd, default_origin='top left')
img_plot1 = plot1.img_plot("imagedata",colormap=gray,padding=0)[0]
img_plot2 = plot2.img_plot("orig",colormap=gray,padding=0)[0]
container = HPlotContainer(plot1,plot2)
container.spacing=0
plot1.padding_right=0
plot2.padding_left=0
plot2.y_axis.orientation= 'right'
return container
示例11: _load_image_data
def _load_image_data(self, data):
cont = HPlotContainer()
pd = ArrayPlotData()
plot = Plot(data=pd, padding=[30, 5, 5, 30], default_origin="top left")
pd.set_data("img", data)
img_plot = plot.img_plot("img")[0]
self._add_inspector(img_plot)
self._add_tools(img_plot)
cont.add(plot)
cont.request_redraw()
self.image_container.container = cont
示例12: _create_plot_component
def _create_plot_component():
# Create some x-y data series to plot
x = linspace(-2.0, 10.0, 100)
pd = ArrayPlotData(index = x)
for i in range(5):
pd.set_data("y" + str(i), jn(i,x))
# Create some line plots of some of the data
plot = Plot(pd, title="Line Plot", padding=50, border_visible=True)
plot.legend.visible = True
plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="auto")
plot.plot(("index", "y3"), name="j_3", color="auto")
plot.x_grid.line_color = "black"
plot.y_grid.line_color = "black"
xmin, xmax = 1.0, 6.0
ymin, ymax = 0.2, 0.80001
plot.x_grid.set(data_min = xmin, data_max = xmax,
transverse_bounds = (ymin, ymax),
transverse_mapper = plot.y_mapper)
plot.y_grid.set(data_min = ymin, data_max = ymax,
transverse_bounds = (xmin, xmax),
transverse_mapper = plot.x_mapper)
# 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)
# A second plot whose vertical grid lines are clipped to the jn(3) function
def my_bounds_func(ticks):
""" Returns y_low and y_high for each grid tick in the array **ticks** """
tmp = array([zeros(len(ticks)),jn(3, ticks)]).T
return tmp
func_plot = Plot(pd, padding=50, border_visible=True)
func_plot.plot(("index", "y3"), color="red")
func_plot.x_grid.set(transverse_bounds = my_bounds_func,
transverse_mapper = func_plot.y_mapper,
line_color="black")
func_plot.tools.append(PanTool(func_plot))
container = HPlotContainer()
container.add(plot)
container.add(func_plot)
return container
示例13: _create_plot_component
def _create_plot_component(model):
# Create a plot data object and give it the model's data array.
pd = ArrayPlotData()
pd.set_data("imagedata", model.data)
# Create the "main" Plot.
plot = Plot(pd, padding=50)
# Use a TransformColorMapper for the color map.
tcm = TransformColorMapper.from_color_map(jet)
# Create the image plot renderer in the main plot.
renderer = plot.img_plot("imagedata",
xbounds=model.x_array,
ybounds=model.y_array,
colormap=tcm)[0]
# Create the colorbar.
lm = LinearMapper(range=renderer.value_range,
domain_limits=(renderer.value_range.low,
renderer.value_range.high))
colorbar = ColorBar(index_mapper=lm,
plot=plot,
orientation='v',
resizable='v',
width=30,
padding=20)
colorbar.padding_top = plot.padding_top
colorbar.padding_bottom = plot.padding_bottom
# Add pan and zoom tools to the colorbar.
colorbar.tools.append(PanTool(colorbar,
constrain_direction="y",
constrain=True))
zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range",
always_on=True, drag_button="right")
colorbar.overlays.append(zoom_overlay)
# Create a container to position the plot and the colorbar side-by-side
container = HPlotContainer(use_backbuffer = True)
container.add(plot)
container.add(colorbar)
return container
示例14: test_valign
def test_valign(self):
container = HPlotContainer(bounds=[300,200], valign="center")
comp1 = StaticPlotComponent([200,100])
container.add(comp1)
container.do_layout()
self.assertEqual(comp1.position, [0,50])
container.valign="top"
container.do_layout(force=True)
self.assertEqual(comp1.position, [0,100])
return
示例15: _create_plot_component
def _create_plot_component():
# Create the index
numpoints = 100
low = -5
high = 15.0
x = arange(low, high, (high - low) / numpoints)
plotdata = ArrayPlotData(x=x, y1=jn(0, x), y2=jn(1, x))
# Create the left plot
left_plot = Plot(plotdata)
left_plot.x_axis.title = "X"
left_plot.y_axis.title = "j0(x)"
renderer = left_plot.plot(("x", "y1"), type="line", color="blue",
width=2.0)[0]
renderer.overlays.append(LineInspector(renderer, axis='value',
write_metadata=True,
is_listener=True))
renderer.overlays.append(LineInspector(renderer, axis="index",
write_metadata=True,
is_listener=True))
left_plot.overlays.append(ZoomTool(left_plot, tool_mode="range"))
left_plot.tools.append(PanTool(left_plot))
# Create the right plot
right_plot = Plot(plotdata)
right_plot.index_range = left_plot.index_range
right_plot.orientation = "v"
right_plot.x_axis.title = "j1(x)"
right_plot.y_axis.title = "X"
renderer2 = right_plot.plot(("x", "y2"), type="line", color="red",
width=2.0)[0]
renderer2.index = renderer.index
renderer2.overlays.append(LineInspector(renderer2, write_metadata=True,
is_listener=True))
renderer2.overlays.append(LineInspector(renderer2, axis="value",
is_listener=True))
right_plot.overlays.append(ZoomTool(right_plot, tool_mode="range"))
right_plot.tools.append(PanTool(right_plot))
container = HPlotContainer(background="lightgray")
container.add(left_plot)
container.add(right_plot)
return container