我正在尝试学习一些chaco,但我在编辑我创建的情节时遇到了问题。我制作了一个四个图的网格,两个散点图和两个条形图。我希望能够去除图之间的空白区域,还可以增加散点图的宽度并减小条形图的宽度。 更改轴标签等简单的事情似乎没有在文档中很好地描述,有谁知道我在哪里可以看到如何做这些事情的一些例子。
我的代码如下,
from chaco.api import ArrayPlotData, Plot, GridPlotContainer
from enable.component_editor import ComponentEditor
from traits.api import HasTraits, Instance
from traitsui.api import View, Item
import numpy as np
import glob
import pickle
class ArrayPlot(HasTraits):
plot = Instance(GridPlotContainer)
traits_view = View(Item('plot', editor = ComponentEditor(), show_label = False),
width = 1000, height = 500,
resizable = True, title = "Joekulheimar")
def __init__(self, time, slow, baz, *args, **kw):
super(ArrayPlot, self).__init__(*args, **kw)
# Create a GridContainer to hold all of our plots: 2 rows, 2 columns
container = GridPlotContainer(shape=(2,2),
spacing=(10.0,0.0),
valign='top',
bgcolor='white')
## plot baz data
# time series
plotdata1 = ArrayPlotData(x=time,y=baz)
plot1 = Plot(plotdata1)
plot1.plot(("x","y"), type = "scatter", color = "blue", marker='circle')
plot1.set(width=30.0, height=20.0, resizable='hv') # does nothing!!!!!!!!!
# histogram
hist, bins = np.histogram(baz, bins=30, density=True)
center = (bins[:-1] + bins[1:]) / 2
width = center[1]-center[0]
plotdata2 = ArrayPlotData(x=center, y=hist)
plot2 = Plot(plotdata2, orientation='v', axis_line_visible=False, resizable = 'hv')
plot2.plot(("x","y"), type = "bar", color = "blue", bar_width=width,
fill_color='green')
plot2.range2d.y_range.low = 0
## plot slow data
# time series
plotdata3 = ArrayPlotData(x=time,y=slow)
plot3 = Plot(plotdata3)
plot3.plot(("x","y"), type = "scatter", color = "blue", marker='circle')
# histogram
hist, bins = np.histogram(slow, bins=30, density=True)
center = (bins[:-1] + bins[1:]) / 2
width = center[1]-center[0]
plotdata4 = ArrayPlotData(x=center,y=hist)
plot4 = Plot(plotdata4, orientation='v', axis_line_visible=False, resizable = 'hv')
xlim=plot4.index_mapper.range
plot4.plot(("x","y"), type = "bar", color = "blue", bar_width=width,
fill_color='green')
plot4.range2d.y_range.low = 0
# Add to the grid container
container.add(plot1, plot2, plot3, plot4)
self.plot = container
TIME = np.linspace(0, 1000, 1000)
SLOW = np.random.randn(1000)
BAZ = np.random.randn(1000)
grid_plot = ArrayPlot(TIME, SLOW, BAZ)
grid_plot.configure_traits()