Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:11:05+00:00 2026-06-05T20:11:05+00:00

The Chaco plotting toolkit for Python includes examples that show how to dynamically update

  • 0

The Chaco plotting toolkit for Python includes examples that show how to dynamically update existing plots. However, my application requires that I dynamically create and destroy plots depending on the data. I am new to programming with Chaco and Traits, so a simple example that illustrates how to do this would be really helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:11:06+00:00Added an answer on June 5, 2026 at 8:11 pm

    This is a bit late, but here’s an example that creates and destroys Chaco plots. The main interface is PlotSelector, which defines some fake data and radio buttons to switch between two different plot styles (line and bar plots).

    This example uses a Traits event to signal when to close a plot, and then handles that signal with PlotController. There may be a better way to close the window, but I couldn’t find one.

    Edit: Updated imports for newer versions of Traits, Chaco, and Enable (ETS 4 instead of 3).

    import numpy as np
    
    import traits.api as traits
    import traitsui.api as ui
    import chaco.api as chaco
    from enable.api import ComponentEditor
    
    
    class PlotController(ui.Controller):
        view = ui.View(ui.Item('plot', editor=ComponentEditor(), show_label=False),
                       height=300, width=300, resizable=True)
    
        def object_close_signal_changed(self, info):
            info.ui.dispose()
    
    
    class BasicPlot(traits.HasTraits):
        close_signal = traits.Event()
        plot = traits.Instance(chaco.Plot)
    
    
    class LinePlot(BasicPlot):
    
        def __init__(self, plotdata):
            self.plot = chaco.Plot(plotdata)
            self.plot.plot(('x', 'y'))
    
    
    class BarPlot(BasicPlot):
    
        def __init__(self, plotdata):
            self.plot = chaco.Plot(plotdata)
            self.plot.candle_plot(('x', 'ymin', 'ymax'))
    
    
    available_plot_types = dict(line=LinePlot, bar=BarPlot)
    
    class PlotSelector(traits.HasTraits):
    
        plot_type = traits.Enum(['line', 'bar'])
        traits_view = ui.View('plot_type', style='custom')
    
        def __init__(self, x, y):
            ymin = y - 1
            ymax = y + 1
            self.plotdata = chaco.ArrayPlotData(x=x, y=y, ymin=ymin, ymax=ymax)
            self.figure = None
    
        def _plot_type_changed(self):
            plot_class = available_plot_types[self.plot_type]
            if self.figure is not None:
                self.figure.close_signal = True
            self.figure = plot_class(self.plotdata)
            controller = PlotController(model=self.figure)
            controller.edit_traits()
    
    
    N = 20
    x = np.arange(N)
    y = x + np.random.normal(size=N)
    plot_selector = PlotSelector(x, y)
    plot_selector.configure_traits()
    

    Note that the main interface (PlotSelector) calls configure_traits (starts application), while the plots are viewed with edit_traits (called from within application). Also, note that this example calls edit_traits from PlotController instead of calling it from the model. You could instead move the view from PlotController to BasicPlot and set the handler method of that view to PlotController.

    Finally, if you don’t need to totally destroy the plot window, then you may want to look at the Plot object’s delplot method, which destroys the *sub*plot (here the line plot or bar plot).

    I hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do i go about adding Chaco to an existing PyQt4 application? Hours of
I recently installed the enthoughts distribution of python and started to go through the
Scott Chacon's Showoff gem is a great alternative to Powerpoint/Keynote... but the fact that
In Pro Git Scott Chacon gives some nice examples of some alias which might
I know that it's a good idea to cache objects that will be used
I am using MEF in a framework to compose worker threads available processors dynamically
I'd love your help understanding the following: Assume that I have a Value of
In Enthought's Chaco, the TimeFormatter class is used to format the time string of
I'm trying to write a program that creates a 2D grid in which the
I have a list of 350 addresses in a single column excel file that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.