本文整理汇总了Python中chaco.api.HPlotContainer.add方法的典型用法代码示例。如果您正苦于以下问题:Python HPlotContainer.add方法的具体用法?Python HPlotContainer.add怎么用?Python HPlotContainer.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chaco.api.HPlotContainer
的用法示例。
在下文中一共展示了HPlotContainer.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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
示例3: _hist2d_default
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
def _hist2d_default(self):
plot = Plot(self.hist2d_data, padding=(20, 0, 0, 40))
plot.img_plot("H", xbounds=self.xedges, ybounds=self.yedges, colormap=jet)
plot.index_axis.title = "Voxel dist."
plot.value_axis.title = "Root Square Error"
# Create a colorbar
colormap = plot.color_mapper
colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
color_mapper=colormap,
plot=plot,
orientation='v',
resizable='v',
width=20,
padding=(20, 30, 0, 0))
colorbar.padding_top = plot.padding_top
colorbar.padding_bottom = plot.padding_bottom
# Create a container to position the plot and the colorbar side-by-side
container = HPlotContainer(use_backbuffer=True, padding=0)
container.add(colorbar)
container.add(plot)
container.bgcolor = "lightgray"
return container
示例4: _container_default
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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
示例5: __init__
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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 a scatter plot
scatter_plot = Plot(plotdata)
scatter_plot.plot(("x", "y"), type="scatter", color="blue")
# Create a line plot
line_plot1 = Plot(plotdata)
line_plot1.plot(("x", "y"), type="line", color="blue")
line_plot2 = Plot(plotdata)
line_plot2.plot(("x", "y"), type="line", color="red")
# Create a vertical container containing two horizontal containers
h_container1 = HPlotContainer()
h_container2 = HPlotContainer()
outer_container = VPlotContainer(h_container1, h_container2,
stack_order="top_to_bottom")
# Add the two plots to the first container
h_container1.add(scatter_plot, line_plot1, line_plot2)
# Now add the first line plot to the second container => it is removed
# from the first, as each plot can only have one container
h_container2.add(line_plot1)
self.plot = outer_container
示例6: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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: _plot_default
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
def _plot_default(self):
plot = Plot(self.plotdata)
plot.title = "Simplex on the Rosenbrock function"
plot.img_plot("background",
name="background",
xbounds=(0,1.5),
ybounds=(0,1.5),
colormap=jet(DataRange1D(low=0,high=100)),
)
plot.plot(("values_x", "values_y"), type="scatter", color="red")
background = plot.plots["background"][0]
colormap = background.color_mapper
colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
color_mapper=colormap,
plot=background,
orientation='v',
resizable='v',
width=30,
padding=20)
colorbar.padding_top = plot.padding_top
colorbar.padding_bottom = plot.padding_bottom
container = HPlotContainer(use_backbuffer = True)
container.add(plot)
container.add(colorbar)
container.bgcolor = "lightgray"
return container
示例8: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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
示例9: control
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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
示例10: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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
示例11: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
def _create_plot_component():
# Create some data
numpts = 1000
x = sort(random(numpts))
y = random(numpts)
color = exp(-(x**2 + y**2))
# Create a plot data obect and give it this data
pd = ArrayPlotData()
pd.set_data("index", x)
pd.set_data("value", y)
pd.set_data("color", color)
# Create the plot
plot = Plot(pd)
plot.plot(("index", "value", "color"),
type="cmap_scatter",
name="my_plot",
color_mapper=jet,
marker = "square",
fill_alpha = 0.5,
marker_size = 6,
outline_color = "black",
border_visible = True,
bgcolor = "white")
# Tweak some of the plot properties
plot.title = "Colormapped Scatter Plot"
plot.padding = 50
plot.x_grid.visible = False
plot.y_grid.visible = False
plot.x_axis.font = "modern 16"
plot.y_axis.font = "modern 16"
# Right now, some of the tools are a little invasive, and we need the
# actual ColomappedScatterPlot object to give to them
cmap_renderer = plot.plots["my_plot"][0]
# Attach some tools to the plot
plot.tools.append(PanTool(plot, constrain_key="shift"))
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
plot.overlays.append(zoom)
selection = ColormappedSelectionOverlay(cmap_renderer, fade_alpha=0.35,
selection_type="mask")
cmap_renderer.overlays.append(selection)
# Create the colorbar, handing in the appropriate range and colormap
colorbar = create_colorbar(plot.color_mapper)
colorbar.plot = cmap_renderer
colorbar.padding_top = plot.padding_top
colorbar.padding_bottom = plot.padding_bottom
# 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 = "lightgray"
return container
示例12: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
def _create_plot_component():
# Load state data
states = pandas.read_csv('states.csv')
lon = (states['longitude'] + 180.) / 360.
lat = numpy.radians(states['latitude'])
lat = (1 - (1. - numpy.log(numpy.tan(lat) +
(1./numpy.cos(lat)))/numpy.pi)/2.0)
populations = pandas.read_csv('state_populations.csv')
data = populations['2010']
lon = lon.view(numpy.ndarray)
lat = lat.view(numpy.ndarray)
data = data.view(numpy.ndarray)
plot = Plot(ArrayPlotData(index = lon, value=lat, color=data))
renderers = plot.plot(("index", "value", "color"),
type = "cmap_scatter",
name = "unfunded",
color_mapper = OrRd,
marker = "circle",
outline_color = 'lightgray',
line_width = 1.,
marker_size = 10,
)
tile_cache = MBTileManager(filename = './map.mbtiles',
min_level = 2,
max_level = 4)
# Need a better way add the overlays
cmap = renderers[0]
map = Map(cmap, tile_cache=tile_cache, zoom_level=3)
cmap.underlays.append(map)
plot.title = "2010 Population"
plot.tools.append(PanTool(plot))
plot.tools.append(ZoomTool(plot))
plot.index_axis.title = "Longitude"
plot.index_axis.tick_label_formatter = convert_lon
plot.value_axis.title = "Latitude"
plot.value_axis.tick_label_formatter = convert_lat
cmap.overlays.append(
ColormappedSelectionOverlay(cmap, fade_alpha=0.35,
selection_type="mask"))
colorbar = create_colorbar(plot.color_mapper)
colorbar.plot = cmap
colorbar.padding_top = plot.padding_top
colorbar.padding_bottom = plot.padding_bottom
container = HPlotContainer(use_backbuffer = True)
container.add(plot)
container.add(colorbar)
container.bgcolor = "lightgray"
return container
示例13: test_valign
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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
示例14: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
def _create_plot_component(max_pop, index_ds, value_ds, color_ds, paths):
tile_cache = HTTPTileManager(min_level=2, max_level=4,
server='tile.cloudmade.com',
url='/1a1b06b230af4efdbb989ea99e9841af/20760/256/%(zoom)d/%(col)d/%(row)d.png') # noqa
color_range = DataRange1D(color_ds, low_setting=0)
choro = ChoroplethPlot(
index=index_ds,
value=value_ds,
color_data=color_ds,
index_mapper=LinearMapper(range=DataRange1D(index_ds)),
value_mapper=LinearMapper(range=DataRange1D(value_ds)),
color_mapper=colormap(range=color_range),
outline_color='white',
line_width=1.5,
fill_alpha=1.,
compiled_paths=paths,
tile_cache=tile_cache,
zoom_level=3,
)
container = OverlayPlotContainer(
bgcolor='sys_window', padding=50, fill_padding=False,
border_visible=True,
)
container.add(choro)
for dir in ['left']:
axis = PlotAxis(tick_label_formatter=convert_lat,
mapper=choro.value_mapper, component=container,
orientation=dir)
container.overlays.append(axis)
for dir in ['top', 'bottom']:
axis = PlotAxis(tick_label_formatter=convert_lon,
mapper=choro.index_mapper, component=container,
orientation=dir)
container.overlays.append(axis)
choro.tools.append(PanTool(choro))
choro.tools.append(ZoomTool(choro))
colorbar = create_colorbar(choro)
colorbar.padding_top = container.padding_top
colorbar.padding_bottom = container.padding_bottom
plt = HPlotContainer(use_backbuffer=True)
plt.add(container)
plt.add(colorbar)
plt.bgcolor = "sys_window"
return plt
示例15: _create_plot_component
# 需要导入模块: from chaco.api import HPlotContainer [as 别名]
# 或者: from chaco.api.HPlotContainer import add [as 别名]
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