1 May 2012 03:03
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:
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
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:ThanksOn 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:UItem is just a subclass of Item with show_label=False. Usually, I don't
> 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?
>
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
RSS Feed