MultiLinePlot problems

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

MultiLinePlot problems

taru
I want build for example 2 line in one window.
Coord lines:
1 polyline:
x = 2,y = 2
x = 3,y = 3
x = 6,y = 6
and second poly:
x = 2, y = 2
x = 4, y = 4
x = 7, y = 9

I choose multi_line_plot.py from ets/chaco/examples/demo

import numpy as np

from chaco.api import LinearMapper, Plot, ArrayDataSource, DataRange1D
from chaco.multi_array_data_source import MultiArrayDataSource
from chaco.multi_line_plot import MultiLinePlot
from enable.api import ComponentEditor
from traits.api import Instance, HasTraits
from traitsui.api import View, UItem

class MyPlot(HasTraits):
    """ Displays a plot with a few buttons to control which overlay
        to display
    """
    plot = Instance(Plot)

    traits_view = View(UItem('plot', editor=ComponentEditor()),
                       width=700, height=600, resizable=True
                       )

    def __init__(self, x_index, y_index, data, **kw):
        super(MyPlot, self).__init__(**kw)

        # Create the data source for the MultiLinePlot.
        ds = MultiArrayDataSource(data=data)

        xs = ArrayDataSource(x_index, sort_order='ascending')
        xrange = DataRange1D()
        xrange.add(xs)

        ys = ArrayDataSource(y_index, sort_order='ascending')
        yrange = DataRange1D()
        yrange.add(ys)

        mlp = MultiLinePlot(
                        index = xs,
                        yindex = ys,
                        index_mapper = LinearMapper(range=xrange),
                        value_mapper = LinearMapper(range=yrange),
                        value=ds,
                        global_max = np.nanmax(data),
                        global_min = np.nanmin(data),
                        **kw)

        self.plot = Plot()
        self.plot.add(mlp)


#x_index = np.arange(0,100, 1)
#y_index = np.arange(0,1000, 10)
#data = np.sin(np.arange(0,x_index.size*y_index.size))
#data = np.array(np.arange(0,x_index.size*y_index.size))
# add a random chunk of nan values
#data[1532:1588] = np.nan
x_index = np.array([0,3]) #<- ?????????? 0,3 - 3 points on X
y_index = np.array([0,3]) #<- ?????????? 0,3 - 3 points on Y
data = np.array([2,2,3,3,6,6,2,2,4,4,7,9]) #<- ??????????
data = data.reshape(x_index.size, y_index.size) #<- ??????????

my_plot = MyPlot(x_index, y_index, data)
my_plot.configure_traits()

I ran and get:
 ValueError: total size of new array must be unchanged

Help me !
thanx


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

Re: MultiLinePlot problems

Brennan Williams
On 20/09/2012 1:22 a.m., taru wrote:

> I want build for example 2 line in one window.
> Coord lines:
> 1 polyline:
> x = 2,y = 2
> x = 3,y = 3
> x = 6,y = 6
> and second poly:
> x = 2, y = 2
> x = 4, y = 4
> x = 7, y = 9
>
> I choose multi_line_plot.py from ets/chaco/examples/demo
>
> import numpy as np
>
> from chaco.api import LinearMapper, Plot, ArrayDataSource, DataRange1D
> from chaco.multi_array_data_source import MultiArrayDataSource
> from chaco.multi_line_plot import MultiLinePlot
> from enable.api import ComponentEditor
> from traits.api import Instance, HasTraits
> from traitsui.api import View, UItem
>
> class MyPlot(HasTraits):
>      """ Displays a plot with a few buttons to control which overlay
>          to display
>      """
>      plot = Instance(Plot)
>
>      traits_view = View(UItem('plot', editor=ComponentEditor()),
>                         width=700, height=600, resizable=True
>                         )
>
>      def __init__(self, x_index, y_index, data, **kw):
>          super(MyPlot, self).__init__(**kw)
>
>          # Create the data source for the MultiLinePlot.
>          ds = MultiArrayDataSource(data=data)
>
>          xs = ArrayDataSource(x_index, sort_order='ascending')
>          xrange = DataRange1D()
>          xrange.add(xs)
>
>          ys = ArrayDataSource(y_index, sort_order='ascending')
>          yrange = DataRange1D()
>          yrange.add(ys)
>
>          mlp = MultiLinePlot(
>                          index = xs,
>                          yindex = ys,
>                          index_mapper = LinearMapper(range=xrange),
>                          value_mapper = LinearMapper(range=yrange),
>                          value=ds,
>                          global_max = np.nanmax(data),
>                          global_min = np.nanmin(data),
>                          **kw)
>
>          self.plot = Plot()
>          self.plot.add(mlp)
>
>
> #x_index = np.arange(0,100, 1)
> #y_index = np.arange(0,1000, 10)
> #data = np.sin(np.arange(0,x_index.size*y_index.size))
> #data = np.array(np.arange(0,x_index.size*y_index.size))
> # add a random chunk of nan values
> #data[1532:1588] = np.nan
> x_index = np.array([0,3]) #<- ?????????? 0,3 - 3 points on X
> y_index = np.array([0,3]) #<- ?????????? 0,3 - 3 points on Y
> data = np.array([2,2,3,3,6,6,2,2,4,4,7,9]) #<- ??????????
> data = data.reshape(x_index.size, y_index.size) #<- ??????????
>
> my_plot = MyPlot(x_index, y_index, data)
> my_plot.configure_traits()
>
> I ran and get:
>   ValueError: total size of new array must be unchanged
>
> Help me !

Your x_index and y_index arrays are [0 3].
If you want them to be [0 1 2] then you need

x_index=np.array(range(0,3))

This still leaves x_index and y_index having length of 3 whereas your
data array has 12 values.

Brennan


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

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

Re: MultiLinePlot problems

taru
Brennan Williams <brennan.williams@...> writes:

>
> On 20/09/2012 1:22 a.m., taru wrote:
> > I want build for example 2 line in one window.
> > Coord lines:
> > 1 polyline:
> > x = 2,y = 2
> > x = 3,y = 3
> > x = 6,y = 6
> > and second poly:
> > x = 2, y = 2
> > x = 4, y = 4
> > x = 7, y = 9
> >
>
> Your x_index and y_index arrays are [0 3].
> If you want them to be [0 1 2] then you need
>
> x_index=np.array(range(0,3))
>
> This still leaves x_index and y_index having length of 3 whereas your
> data array has 12 values.
>
> Brennan
>

I try x(y)_index=np.array(range(0,3)) or np.array([0,1,2]) ...
data.reshape(12,1 ... 1,12 ... 4,3 .... 3,4....)
Wrong chart or a blank window.

What should be in your opinion the following parameters:
x_index - ????
y_index - ????
data - ????
data.reshape(???,????)


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

Re: MultiLinePlot problems

Brennan Williams
On 20/09/2012 11:16 a.m., taru wrote:

> Brennan Williams <brennan.williams@...> writes:
>
>> On 20/09/2012 1:22 a.m., taru wrote:
>>> I want build for example 2 line in one window.
>>> Coord lines:
>>> 1 polyline:
>>> x = 2,y = 2
>>> x = 3,y = 3
>>> x = 6,y = 6
>>> and second poly:
>>> x = 2, y = 2
>>> x = 4, y = 4
>>> x = 7, y = 9
>>>
>> Your x_index and y_index arrays are [0 3].
>> If you want them to be [0 1 2] then you need
>>
>> x_index=np.array(range(0,3))
>>
>> This still leaves x_index and y_index having length of 3 whereas your
>> data array has 12 values.
>>
>> Brennan
>>
> I try x(y)_index=np.array(range(0,3)) or np.array([0,1,2]) ...
> data.reshape(12,1 ... 1,12 ... 4,3 .... 3,4....)
> Wrong chart or a blank window.
>
> What should be in your opinion the following parameters:
> x_index - ????
> y_index - ????
> data - ????
> data.reshape(???,????)
If your x and y index arrays are of length 3 then reshaping data to 3,3
means data has to be of length 9 rather than 12.

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

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