Warren Weckesser | 1 May 2012 03:03
Gravatar

Re: Setting axis values of a chaco plot



On Mon, Apr 30, 2012 at 4:54 PM, Adam Hughes <hugadams-X40cu4teqwPD0P1m9PE5KA@public.gmane.org> wrote:
Hi Warren,

I implemented this solution into my plot but noticed that I'm only seeing the first label.  For example X1.  I am plotting multiple lines, each one having several hundred points; however, I don't see how this should affect my axis.  I don't quite understand what the labels and positions are, so maybe this is the problem.  Have you ever experienced this?



The Label axis will still apply an algorithm to determine which labels to display.  It will not display all the labels if they are too close together.  If you have a ZoomTool on your plot, try zooming in and see if the labels appear.

Warren



On Sun, Apr 29, 2012 at 5:28 PM, Adam Hughes <hugadams-X40cu4teqwPD0P1m9PE5KA@public.gmane.org> wrote:
Thanks


On Sun, Apr 29, 2012 at 5:18 PM, Warren Weckesser <warren.weckesser-SCgzsaguwNrby3iVrkZq2A@public.gmane.org> wrote:
On Sun, Apr 29, 2012 at 4:06 PM, Adam Hughes <hugadams <at> gwmail.gwu.edu>wrote:

> Thanks Warren, just what I was looking for.  I appreciate it.
>
> Is there any advantage to using UItem in this case to store my plot
> variable than just Item?
>


UItem is just a subclass of Item with show_label=False.  Usually, I don't
want an Item label next to a plot.

Warren



>
> On Sun, Apr 29, 2012 at 4:43 PM, Warren Weckesser <
> warren.weckesser-SCgzsaguwNrby3iVrkZq2A@public.gmane.org> wrote:
>
> > On Sun, Apr 29, 2012 at 3:03 PM, Adam Hughes <hugadams-X40cu4teqwPD0P1m9PE5KA@public.gmane.org
> > >wrote:
> >
> > > Hi,
> > >
> > > If I have a Plot object and I want to set the axis values to a set of
> > > strings.  For example, if by default they are:
> > >
> > > '1', '2', '3'
> > >
> > > and I want to force the axis to be
> > >
> > > 'Test 1', 'Test 2', 'Test 3'
> > >
> > > What is the best way to do this?  In the demo, I found a process in
> which
> > > one had to invoke mappers and three intermediate objects
> "LinearMapper",
> > > "ArrayDataSource" and PlotAxis" objects:
> > >
> > >        x=ArrayDataSource(self.xlabel)
> > >        xmapper = LinearMapper(range=DataRange1D(x))
> > >        bottom_axis = PlotAxis(plot, orientation="bottom",
> mapper=xmapper)
> > >        plot.overlays.append(bottom_axis)
> > >
> > > Is this still the primary way to do it?  I wasn't sure if in more
> recent
> > > versions of chaco, some of this may have been streamlined through a new
> > > function call or something that isn't reflected in the API.
> > >
> > > Thanks.
> > >
> >
> >
> > Adam,
> >
> > You can replace the default axis (a PlotAxis) with a LabelAxis.  Here's
> an
> > example:
> >
> > -----
> >
> > import numpy as np
> >
> > from traits.api import HasTraits, Instance
> > from traitsui.api import View, UItem
> > from enable.api import ComponentEditor
> > from chaco.api import Plot, ArrayPlotData, LabelAxis
> > from chaco.tools.api import PanTool, ZoomTool
> >
> >
> > class Demo(HasTraits):
> >
> >    data = Instance(ArrayPlotData)
> >
> >    plot = Instance(Plot)
> >
> >    traits_view = \
> >        View(
> >            UItem('plot', editor=ComponentEditor(size=(60, 60))),
> >            width=500,
> >            height=500,
> >            resizable=True,
> >        )
> >
> >    def _data_default(self):
> >        x = np.linspace(0, 5, 501)
> >        y = np.sin(np.pi * np.exp(0.25 * x))
> >        data = ArrayPlotData(x=x, y=y)
> >        return data
> >
> >    def _plot_default(self):
> >        plot = Plot(self.data)
> >        plot.plot(('x', 'y'))
> >
> >        # Add pan and zoom tools.
> >        plot.tools.append(PanTool(plot))
> >        plot.overlays.append(ZoomTool(plot))
> >
> >        # Replace the x axis labels with text labels.
> >        label_axis = LabelAxis(plot, orientation='bottom',
> >                               positions=range(6),
> >                               labels=['X0', 'X1', 'X2', 'X3', 'X4',
> 'X5'])
> >        plot.index_axis = label_axis
> >
> >        return plot
> >
> >
> > if __name__ == "__main__":
> >    demo = Demo()
> >    demo.configure_traits()
> >
> > -----
> >
> >
> > Warren
> > _______________________________________________
> > Enthought-Dev mailing list
> > Enthought-Dev-oRDGkvazHdacsI7C1d+pp9BPR1lH4CV8@public.gmane.org
> > https://mail.enthought.com/mailman/listinfo/enthought-dev
> >
> _______________________________________________
> Enthought-Dev mailing list
> Enthought-Dev-oRDGkvazHdacsI7C1d+pp9BPR1lH4CV8@public.gmane.org
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
Enthought-Dev-oRDGkvazHdacsI7C1d+pp9BPR1lH4CV8@public.gmane.org
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
Enthought-Dev-oRDGkvazHdbtRgLqZ5aouw@public.gmane.orgought.com
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Warren Weckesser | 1 May 2012 03:47
Gravatar

Trying to attach a python file

Just checking if the mailing list now accepts python files as attachments.  Did you get an attachment? (One reply from someone is all I need :)

Warren

Attachment (chaco_axis_labels_demo.py): application/octet-stream, 1269 bytes
_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Tim Diller | 1 May 2012 04:01
Gravatar

Re: Trying to attach a python file

yes.



On Mon, Apr 30, 2012 at 8:47 PM, Warren Weckesser <warren.weckesser <at> enthought.com> wrote:
Just checking if the mailing list now accepts python files as attachments.  Did you get an attachment? (One reply from someone is all I need :)

Warren


_______________________________________________
Enthought-Dev mailing list
Enthought-Dev-oRDGkvazHdbtRgLqZ5aouw@public.gmane.orgought.com
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Warren Weckesser | 1 May 2012 04:02
Gravatar

Re: Trying to attach a python file


On Mon, Apr 30, 2012 at 9:01 PM, Tim Diller <tdiller-SCgzsaguwNrby3iVrkZq2A@public.gmane.org> wrote:
yes.

 
Great, thanks.





On Mon, Apr 30, 2012 at 8:47 PM, Warren Weckesser <warren.weckesser-SCgzsaguwNrby3iVrkZq2A@public.gmane.org> wrote:
Just checking if the mailing list now accepts python files as attachments.  Did you get an attachment? (One reply from someone is all I need :)

Warren




_______________________________________________
Enthought-Dev mailing list
Enthought-Dev-oRDGkvazHdbtRgLqZ5aouw@public.gmane.orgought.com
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Adam Hughes | 1 May 2012 06:38
Picon

Re: Trying to attach a python file

Didn't the last time this bug was observed it was tracked down to the mailing list wouldn't send files with certain file extensions?  For example .txt files.

On Mon, Apr 30, 2012 at 10:02 PM, Warren Weckesser <warren.weckesser-SCgzsaguwNrby3iVrkZq2A@public.gmane.org> wrote:

On Mon, Apr 30, 2012 at 9:01 PM, Tim Diller <tdiller-SCgzsaguwNrby3iVrkZq2A@public.gmane.org> wrote:
yes.

 
Great, thanks.





On Mon, Apr 30, 2012 at 8:47 PM, Warren Weckesser <warren.weckesser <at> enthought.com> wrote:
Just checking if the mailing list now accepts python files as attachments.  Did you get an attachment? (One reply from someone is all I need :)

Warren




_______________________________________________
Enthought-Dev mailing list
Enthought-Dev-oRDGkvazHdacsI7C1d+pp9BPR1lH4CV8@public.gmane.org
https://mail.enthought.com/mailman/listinfo/enthought-dev



_______________________________________________
Enthought-Dev mailing list
Enthought-Dev-oRDGkvazHdbtRgLqZ5aouw@public.gmane.orgought.com
https://mail.enthought.com/mailman/listinfo/enthought-dev


_______________________________________________
Enthought-Dev mailing list
Enthought-Dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Brennan Williams | 1 May 2012 11:09

add_trait

Quick questions... if I use add_trait to add a number of traits with 
value to an instance of an object, how do I check those traits?
I've tried objectname.trait_get() and also objectname.get_trait(name).
I'll put a code snippet together asap.

Brennan
Andrea Crotti | 1 May 2012 11:33
Picon

Re: automated testing and exceptions swallowed

On 04/30/2012 02:57 PM, Robert Kern wrote:
>
> With a little bit of care, this can be made true. For example, main.py
> could use absolute imports, "from mypackage import foo". I recommend
> following through with my suggestions to see who is importing it and
> how. It is likely that you can just fix one of them. It's worth
> fixing, even if you do stop using the global variable.
>

I did a couple of more experiments and still no luck, I don't have time 
to investigate
now and anyway I would not like a solution that is not 100% reliable.

I think I'll change approach, so instead of trying to disable exception 
handling I'll just push
another exception handler, which will call exit when something is raised..
Andrea Crotti | 1 May 2012 12:21
Picon

Re: automated testing and exceptions swallowed

This is getting quite funny, there is absolutely no way that I can get 
the application to quit on exception apparently.
Now I commented out all our code to catch the exceptions and I did

def quit_on_error(object, trait_name, old_value, new_value):
     print("quitting because an exception was raised")
     exit(1)

push_exception_handler(quit_on_error, main=True, locked=True)

but nothing, I can still see the traceback in the shell but the 
application won't die..
Robert Kern | 1 May 2012 12:43
Gravatar

Re: automated testing and exceptions swallowed

On Tue, May 1, 2012 at 11:21 AM, Andrea Crotti
<andrea.crotti.0 <at> gmail.com> wrote:
> This is getting quite funny, there is absolutely no way that I can get the
> application to quit on exception apparently.
> Now I commented out all our code to catch the exceptions and I did
>
> def quit_on_error(object, trait_name, old_value, new_value):
>    print("quitting because an exception was raised")
>    exit(1)
>
> push_exception_handler(quit_on_error, main=True, locked=True)
>
> but nothing, I can still see the traceback in the shell but the application
> won't die..

Can you provide more information? What tracebacks are you seeing? Note
that these handlers are only for errors that are raised by trait
notification handlers, e.g. those that are raised inside
_<foo>_changed() methods. These exception handlers don't get called
for trait validation, for example. The GUI toolkits themselves
typically print-and-ignore exceptions that rise to the main event
loop. They do not stop the application.

--

-- 
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
Enthought-Dev <at> mail.enthought.com
https://mail.enthought.com/mailman/listinfo/enthought-dev
Robert Kern | 1 May 2012 12:45
Gravatar

Re: add_trait

On Tue, May 1, 2012 at 10:09 AM, Brennan Williams
<brennan.williams@...> wrote:
> Quick questions... if I use add_trait to add a number of traits with
> value to an instance of an object, how do I check those traits?
> I've tried objectname.trait_get() and also objectname.get_trait(name).
> I'll put a code snippet together asap.

I'm not sure what you mean by "check those traits". You mean that you
want to see the TraitType that was added for that trait?

[~]
|1> from traits.api import *

[~]
|2> class A(HasTraits):
..>     pass
..>

[~]
|3> a = A()

[~]
|4> a.add_trait('x', Int(10))

[~]
|5> ct = a.trait('x')

[~]
|6> ct
<traits.traits.CTrait at 0x6a2f608>

[~]
|7> %see ct
    ()                    hash()                help()                repr()
    str()                 .cast()               .clone()
    .comparison_mode()    .default              .default_kind
    .default_value()      .default_value_for()  .delegate()
    .full_info()          .get_editor()         .get_help()
    .get_validate()       .handler()            .info()
    .inner_traits         .is_mapped()          .is_trait_type()
    .post_setattr         .post_setattr_original_value()
    .property()           .rich_comparison()    .set_validate()
    .setattr_original_value()                   .trait_type()         .type
    .validate()           .value_allowed()      .value_property()

[~]
|9> ct.trait_type
<traits.trait_types.Int at 0x6a28f30>

[~]
|10> ct.trait_type.default_value
10

--

-- 
Robert Kern
Enthought

Gmane