LabelAxis orientation left/right not working

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

LabelAxis orientation left/right not working

Adam Hughes
Hi,

I've noticed that I can get LabelAxis to give me desired behavior when the orientation is "top" or "bottom" but not when it is "left" or "right".  Although my implementation is different, I've copied an example from the chaco trunk, the barplot with labeled months as the index axis.  What I'd like to do is also add months along the left/right axis (just for the sake of demonstrating the issues).  I've tried several variations of it.  If you use the code below with orientations set to top/bottom, everything works, but use left/right for either orientation and the axis is not correctly formatted.

Am I doing something wrong or is this a bug?

# Major library imports
import numpy

# Enthought library imports
from enable.api import ComponentEditor
from traits.api import HasTraits, Instance
from traitsui.api import UItem, View

# Chaco imports
from chaco.api import LabelAxis, Plot, ArrayPlotData

class PlotExample(HasTraits):
    plot = Instance(Plot)
    traits_view = View(UItem('plot', editor=ComponentEditor()),
                       width=400, height=400, resizable=True, 
                      )

    def __init__(self, index, series_a, series_b, series_c, **kw):
        super(PlotExample, self).__init__(**kw)

        plot_data = ArrayPlotData(index=index)
        plot_data.set_data('series_a', series_a)
        plot_data.set_data('series_b', series_b)
        plot_data.set_data('series_c', series_c)
        self.plot = Plot(plot_data)
        self.plot.plot(('index', 'series_a'), type='bar', bar_width=0.8, color='auto')
        self.plot.plot(('index', 'series_b'), type='bar', bar_width=0.8, color='auto')
        self.plot.plot(('index', 'series_c'), type='bar', bar_width=0.8, color='auto')

        # set the plot's value range to 0, otherwise it may pad too much
        self.plot.value_range.low = 0

        # replace the index values with some nicer labels
        label_axis = LabelAxis(self.plot, orientation='left',
                               title='INDEX AXIS Months',
                               positions = range(1, 10),
                               labels = ['jan', 'feb', 'march', 'april', 'may'],
                               small_haxis_style=True)
        
        v_axis = LabelAxis(self.plot, orientation='top',
                       title='VALUE AXIS Months',
                       positions = range(1, 10),
                       labels = ['jan', 'feb', 'march', 'april', 'may'],
                       small_haxis_style=True)

        self.plot.underlays.remove(self.plot.index_axis) 
        self.plot.underlays.remove(self.plot.value_axis) 
        
        self.plot.index_axis = label_axis
        self.plot.value_axis = v_axis
        
        self.plot.underlays.append(label_axis)
        self.plot.underlays.append(v_axis)


index = numpy.array([1,2,3,4,5])
demo = PlotExample(index, index*10, index*5, index*2)

if __name__ == "__main__":
    demo.configure_traits()

--
Adam Hughes
Physics Ph.D Candidate
George Washington University

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: LabelAxis orientation left/right not working

Jaidev Deshpande
Hi,

On Thu, Feb 28, 2013 at 3:06 AM, Adam Hughes <[hidden email]> wrote:

> Hi,
>
> I've noticed that I can get LabelAxis to give me desired behavior when the
> orientation is "top" or "bottom" but not when it is "left" or "right".
> Although my implementation is different, I've copied an example from the
> chaco trunk, the barplot with labeled months as the index axis.  What I'd
> like to do is also add months along the left/right axis (just for the sake
> of demonstrating the issues).  I've tried several variations of it.  If you
> use the code below with orientations set to top/bottom, everything works,
> but use left/right for either orientation and the axis is not correctly
> formatted.
>
> Am I doing something wrong or is this a bug?
>
> # Major library imports
> import numpy
>
> # Enthought library imports
> from enable.api import ComponentEditor
> from traits.api import HasTraits, Instance
> from traitsui.api import UItem, View
>
> # Chaco imports
> from chaco.api import LabelAxis, Plot, ArrayPlotData
>
> class PlotExample(HasTraits):
>     plot = Instance(Plot)
>     traits_view = View(UItem('plot', editor=ComponentEditor()),
>                        width=400, height=400, resizable=True,
>                       )
>
>     def __init__(self, index, series_a, series_b, series_c, **kw):
>         super(PlotExample, self).__init__(**kw)
>
>         plot_data = ArrayPlotData(index=index)
>         plot_data.set_data('series_a', series_a)
>         plot_data.set_data('series_b', series_b)
>         plot_data.set_data('series_c', series_c)
>         self.plot = Plot(plot_data)
>         self.plot.plot(('index', 'series_a'), type='bar', bar_width=0.8,
> color='auto')
>         self.plot.plot(('index', 'series_b'), type='bar', bar_width=0.8,
> color='auto')
>         self.plot.plot(('index', 'series_c'), type='bar', bar_width=0.8,
> color='auto')
>
>         # set the plot's value range to 0, otherwise it may pad too much
>         self.plot.value_range.low = 0
>
>         # replace the index values with some nicer labels
>         label_axis = LabelAxis(self.plot, orientation='left',
>                                title='INDEX AXIS Months',
>                                positions = range(1, 10),
>                                labels = ['jan', 'feb', 'march', 'april',
> 'may'],
>                                small_haxis_style=True)
>
>         v_axis = LabelAxis(self.plot, orientation='top',
>                        title='VALUE AXIS Months',
>                        positions = range(1, 10),
>                        labels = ['jan', 'feb', 'march', 'april', 'may'],
>                        small_haxis_style=True)
>
>         self.plot.underlays.remove(self.plot.index_axis)
>         self.plot.underlays.remove(self.plot.value_axis)
>
>         self.plot.index_axis = label_axis
>         self.plot.value_axis = v_axis
>
>         self.plot.underlays.append(label_axis)
>         self.plot.underlays.append(v_axis)
>
>
> index = numpy.array([1,2,3,4,5])
> demo = PlotExample(index, index*10, index*5, index*2)
>
> if __name__ == "__main__":
>     demo.configure_traits()
>
> --
> Adam Hughes
> Physics Ph.D Candidate
> George Washington University
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>

I don't know why this is happening, but if you simply want to make it
work, you can use an OverlayPlotContainer instead of a Plot and simply
append the LabelAxis objects to the overlays. This is what's been done
in the tornado plot example
(http://docs.enthought.com/chaco/user_manual/annotated_examples.html#tornado-py),
where the LabelAxis objects are appended to a container and not a
plot.

HTH

--
JD
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: LabelAxis orientation left/right not working

Adam Hughes
Thanks JD,

Not sure I can afford to do this.  My plot object is pretty integrally dependent on the plot object as it has a custom AbstractPlotData source and various calls to plots, both of which do no appear in OverlayPlotContainer.

Will try to get to the bottom of this.

On Wed, Feb 27, 2013 at 5:38 PM, Jaidev Deshpande <[hidden email]> wrote:
Hi,

On Thu, Feb 28, 2013 at 3:06 AM, Adam Hughes <[hidden email]> wrote:
> Hi,
>
> I've noticed that I can get LabelAxis to give me desired behavior when the
> orientation is "top" or "bottom" but not when it is "left" or "right".
> Although my implementation is different, I've copied an example from the
> chaco trunk, the barplot with labeled months as the index axis.  What I'd
> like to do is also add months along the left/right axis (just for the sake
> of demonstrating the issues).  I've tried several variations of it.  If you
> use the code below with orientations set to top/bottom, everything works,
> but use left/right for either orientation and the axis is not correctly
> formatted.
>
> Am I doing something wrong or is this a bug?
>
> # Major library imports
> import numpy
>
> # Enthought library imports
> from enable.api import ComponentEditor
> from traits.api import HasTraits, Instance
> from traitsui.api import UItem, View
>
> # Chaco imports
> from chaco.api import LabelAxis, Plot, ArrayPlotData
>
> class PlotExample(HasTraits):
>     plot = Instance(Plot)
>     traits_view = View(UItem('plot', editor=ComponentEditor()),
>                        width=400, height=400, resizable=True,
>                       )
>
>     def __init__(self, index, series_a, series_b, series_c, **kw):
>         super(PlotExample, self).__init__(**kw)
>
>         plot_data = ArrayPlotData(index=index)
>         plot_data.set_data('series_a', series_a)
>         plot_data.set_data('series_b', series_b)
>         plot_data.set_data('series_c', series_c)
>         self.plot = Plot(plot_data)
>         self.plot.plot(('index', 'series_a'), type='bar', bar_width=0.8,
> color='auto')
>         self.plot.plot(('index', 'series_b'), type='bar', bar_width=0.8,
> color='auto')
>         self.plot.plot(('index', 'series_c'), type='bar', bar_width=0.8,
> color='auto')
>
>         # set the plot's value range to 0, otherwise it may pad too much
>         self.plot.value_range.low = 0
>
>         # replace the index values with some nicer labels
>         label_axis = LabelAxis(self.plot, orientation='left',
>                                title='INDEX AXIS Months',
>                                positions = range(1, 10),
>                                labels = ['jan', 'feb', 'march', 'april',
> 'may'],
>                                small_haxis_style=True)
>
>         v_axis = LabelAxis(self.plot, orientation='top',
>                        title='VALUE AXIS Months',
>                        positions = range(1, 10),
>                        labels = ['jan', 'feb', 'march', 'april', 'may'],
>                        small_haxis_style=True)
>
>         self.plot.underlays.remove(self.plot.index_axis)
>         self.plot.underlays.remove(self.plot.value_axis)
>
>         self.plot.index_axis = label_axis
>         self.plot.value_axis = v_axis
>
>         self.plot.underlays.append(label_axis)
>         self.plot.underlays.append(v_axis)
>
>
> index = numpy.array([1,2,3,4,5])
> demo = PlotExample(index, index*10, index*5, index*2)
>
> if __name__ == "__main__":
>     demo.configure_traits()
>
> --
> Adam Hughes
> Physics Ph.D Candidate
> George Washington University
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>

I don't know why this is happening, but if you simply want to make it
work, you can use an OverlayPlotContainer instead of a Plot and simply
append the LabelAxis objects to the overlays. This is what's been done
in the tornado plot example
(http://docs.enthought.com/chaco/user_manual/annotated_examples.html#tornado-py),
where the LabelAxis objects are appended to a container and not a
plot.

HTH

--
JD
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev



--
Adam Hughes
Physics Ph.D Candidate
George Washington University

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev