Note
This section is currently under active development.
How do I...
def save_plot(plot, filename, width, height):
plot.outer_bounds = [width, height]
plot.do_layout(force=True)
gc = PlotGraphicsContext((width, height), dpi=72)
gc.render_component(plot)
gc.save(filename)
import numpy
from enthought.chaco.api import Plot, ArrayPlotData
from enthought.enable.enable_component import EnableComponent
from enthought.traits.api import HasTraits, Instance
from enthought.traits.ui.api import Item, View
class MyPlot(HasTraits):
plot = Instance(Plot)
traits_view = View(Item('plot', editor=ComponentEditor()))
def __init__(self, index, data_series, **kw):
super(MyPlot, self).__init__(**kw)
plot_data = ArrayPlotData(index=index)
plot_data.set_data('data_series', data_series)
self.plot = Plot(plot_data)
self.plot.plot(('index', 'data_series'))
index = numpy.array([1,2,3,4,5])
data_series = index**2
my_plot = MyPlot(index, data_series)
my_plot.configure_traits()
def plot_several_series(index, series_list):
plot_data = ArrayPlotData(index=index)
plot = Plot(plot_data)
for i, data_series in enumerate(series_list):
series_name = "series_%d" % i
plot_data.set_data(series_name, data_series)
plot.plot(('index', series_name))
def resize_plot(plot, width, height):
plot.outer_bounds = [width, height]
def copy_to_clipboard(plot):
# WX specific, though QT implementation is similar using
# QImage and QClipboard
import wx
width, height = plot.outer_bounds
gc = PlotGraphicsContext((width, height), dpi=72)
gc.render_component(plot_component)
# Create a bitmap the same size as the plot
# and copy the plot data to it
bitmap = wx.BitmapFromBufferRGBA(width+1, height+1,
gc.bmp_array.flatten())
data = wx.BitmapDataObject()
data.SetBitmap(bitmap)
if wx.TheClipboard.Open():
wx.TheClipboard.SetData(data)
wx.TheClipboard.Close()
else:
wx.MessageBox("Unable to open the clipboard.", "Error")
How do I...
def make_black_plot(index, data_series):
plot_data = ArrayPlotData(index=index)
plot_data.set_data('data_series', data_series)
plot = Plot(plot_data, bgcolor='black')
plot.plot(('index', 'data_series'))
def change_bgcolor(plot):
plot.bgcolor = 'black'
def make_borderless_plot(index, data_series):
plot_data = ArrayPlotData(index=index)
plot_data.set_data('data_series', data_series)
plot = Plot(plot_data, border_visible=False)
plot.plot(('index', 'data_series'))
def change_to_borderless_plot(plot):
plot.border_visible = False
How do I...
How do I...