AbstractDataSource and AbstractPlotData

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

AbstractDataSource and AbstractPlotData

Tiago Pereira
Hello,

In the absence of detailed documentation, I was wondering if someone
could help me understand the difference between AbstractDataSource and
AbstractPlotData. If I understand correctly, AbstractDataSource (and
classes that inherit it) is used to wrap data that is going to be
handled by a plot, but from the little documentation for
AbstractPlotData, it also seems to serve the same purpose although it's
used in a different way, and seems to lack metadata. When should one or
the other be used?

Take an example. I am plotting a 2D array representing an image. From
Chaco's examples this seems to be accomplished with:

pd = ArrayPlotData()
pd.set_data("imagedata", my_array)
plot = Plot(pd)
plot.img_plot("imagedata")

(ArrayPlotData being derived from AbstractPlotData)

However, some other examples with contourmaps seem to use the following
approach:

image_index = GridDataSource(my_array1, my_array2)
image_value = ImageData(data=my_array)
CMapImagePlot(index = image_index, value = image_value)

(GridDataSource and ImageData being derived from AbstractDataSource.)

Both of this approaches produce a colormapped image, but one makes use
of AbstractDataSource and AbstractPlotData. When should either be used?

I note that AbstractDataSource has the advantange of saving the
metadata, which in 'selections' has information from tools such as mouse
position and selections. (I also understand that my second example can
be used for irregular grids.)

Also, if using the ArrayPlotData path, and building some tool from
BaseTool, is there any communication method between the tool and the
plot (similar to metadata in ImageData)? I saw the example tool that
prints event.x and event.y on normal_mouse_move, but did not see an
obvious communication if I want to use these values from the plot itself
(or a class calling the plot).

Thanks again,

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

Re: AbstractDataSource and AbstractPlotData

Pietro Berkes
Hi Tiago!

On Mon, Jul 16, 2012 at 8:18 AM, Tiago Pereira <[hidden email]> wrote:
Hello,

In the absence of detailed documentation, I was wondering if someone
could help me understand the difference between AbstractDataSource and
AbstractPlotData. If I understand correctly, AbstractDataSource (and
classes that inherit it) is used to wrap data that is going to be
handled by a plot, but from the little documentation for
AbstractPlotData, it also seems to serve the same purpose although it's
used in a different way, and seems to lack metadata. When should one or
the other be used?

This page of the documentation describes the data sources in Chaco:

http://docs.enthought.com/chaco/user_manual/basic_elements/data_sources.html

"AbstractDataSource" is the most basic interface for all data sources. Any data source in Chaco will at least implement that functionality. "AbstractPlotData" is a more refined interface, which is implemented by more specialized plot data sources.  In general, you should use the concrete implementations of these interfaces, unless you want to write your own data source. The implementations in Chaco are listed on the same page:

http://docs.enthought.com/chaco/user_manual/basic_elements/data_sources.html#list-of-chaco-data-sources


 

Take an example. I am plotting a 2D array representing an image. From
Chaco's examples this seems to be accomplished with:

pd = ArrayPlotData()
pd.set_data("imagedata", my_array)
plot = Plot(pd)
plot.img_plot("imagedata")

(ArrayPlotData being derived from AbstractPlotData)

However, some other examples with contourmaps seem to use the following
approach:

image_index = GridDataSource(my_array1, my_array2)
image_value = ImageData(data=my_array)
CMapImagePlot(index = image_index, value = image_value)

(GridDataSource and ImageData being derived from AbstractDataSource.)

Both of this approaches produce a colormapped image, but one makes use
of AbstractDataSource and AbstractPlotData. When should either be used?

plot.img_plot interprets the input data and creates a GridDataSource and an ImageData object for you, behind the scene. The Plot class offers a simplified user interface to build plots. The second example builds a plot "from" scratch, by creating the data sources and connecting them to a concrete plot renderer (http://docs.enthought.com/chaco/user_manual/basic_elements/plot_renderers.html).

You may use Plot if you need a simple way to create a standard plot. The second method gives you more flexibility and access to the data source, e.g. in case you need to update them to react to some event in your application.

Best,
Pietro


 

I note that AbstractDataSource has the advantange of saving the
metadata, which in 'selections' has information from tools such as mouse
position and selections. (I also understand that my second example can
be used for irregular grids.)

Also, if using the ArrayPlotData path, and building some tool from
BaseTool, is there any communication method between the tool and the
plot (similar to metadata in ImageData)? I saw the example tool that
prints event.x and event.y on normal_mouse_move, but did not see an
obvious communication if I want to use these values from the plot itself
(or a class calling the plot).

Thanks again,

Tiago
_______________________________________________
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: AbstractDataSource and AbstractPlotData

Robert Kern
On Mon, Jul 16, 2012 at 8:53 AM, Pietro Berkes <[hidden email]> wrote:

> Hi Tiago!
>
> On Mon, Jul 16, 2012 at 8:18 AM, Tiago Pereira <[hidden email]> wrote:
>>
>> Hello,
>>
>> In the absence of detailed documentation, I was wondering if someone
>> could help me understand the difference between AbstractDataSource and
>> AbstractPlotData. If I understand correctly, AbstractDataSource (and
>> classes that inherit it) is used to wrap data that is going to be
>> handled by a plot, but from the little documentation for
>> AbstractPlotData, it also seems to serve the same purpose although it's
>> used in a different way, and seems to lack metadata. When should one or
>> the other be used?
>
>
> This page of the documentation describes the data sources in Chaco:
>
> http://docs.enthought.com/chaco/user_manual/basic_elements/data_sources.html
>
> "AbstractDataSource" is the most basic interface for all data sources. Any
> data source in Chaco will at least implement that functionality.
> "AbstractPlotData" is a more refined interface, which is implemented by more
> specialized plot data sources.

In particular, AbstractPlotData is really only there to support the
Plot class, which manages multiple plots on the same set of axes.
AbstractPlotData has a dict-like model mapping names to arrays. Plot
requests data by name, then hooks up the data to an appropriate
AbstractDataSource to feed into the Chaco renderers. So the
AbstractDataSources are still there underneath, and any tools attached
to the renderers will find them just fine.

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

Re: AbstractDataSource and AbstractPlotData

Tiago Pereira
In reply to this post by Pietro Berkes
Thank you Pietro and Robert, it is now much more clear.

Cheers,

Tiago

On 16/7/12 12:53 AM, Pietro Berkes wrote:

> Hi Tiago!
>
> On Mon, Jul 16, 2012 at 8:18 AM, Tiago Pereira <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hello,
>
>     In the absence of detailed documentation, I was wondering if someone
>     could help me understand the difference between AbstractDataSource and
>     AbstractPlotData. If I understand correctly, AbstractDataSource (and
>     classes that inherit it) is used to wrap data that is going to be
>     handled by a plot, but from the little documentation for
>     AbstractPlotData, it also seems to serve the same purpose although it's
>     used in a different way, and seems to lack metadata. When should one or
>     the other be used?
>
>
> This page of the documentation describes the data sources in Chaco:
>
> http://docs.enthought.com/chaco/user_manual/basic_elements/data_sources.html
>
> "AbstractDataSource" is the most basic interface for all data sources.
> Any data source in Chaco will at least implement that functionality.
> "AbstractPlotData" is a more refined interface, which is implemented by
> more specialized plot data sources.  In general, you should use the
> concrete implementations of these interfaces, unless you want to write
> your own data source. The implementations in Chaco are listed on the
> same page:
>
> http://docs.enthought.com/chaco/user_manual/basic_elements/data_sources.html#list-of-chaco-data-sources
>
>
>  
>
>
>     Take an example. I am plotting a 2D array representing an image. From
>     Chaco's examples this seems to be accomplished with:
>
>     pd = ArrayPlotData()
>     pd.set_data("imagedata", my_array)
>     plot = Plot(pd)
>     plot.img_plot("imagedata")
>
>     (ArrayPlotData being derived from AbstractPlotData)
>
>     However, some other examples with contourmaps seem to use the following
>     approach:
>
>     image_index = GridDataSource(my_array1, my_array2)
>     image_value = ImageData(data=my_array)
>     CMapImagePlot(index = image_index, value = image_value)
>
>     (GridDataSource and ImageData being derived from AbstractDataSource.)
>
>     Both of this approaches produce a colormapped image, but one makes use
>     of AbstractDataSource and AbstractPlotData. When should either be used?
>
>
> plot.img_plot interprets the input data and creates a GridDataSource and
> an ImageData object for you, behind the scene. The Plot class offers a
> simplified user interface to build plots. The second example builds a
> plot "from" scratch, by creating the data sources and connecting them to
> a concrete plot renderer
> (http://docs.enthought.com/chaco/user_manual/basic_elements/plot_renderers.html).
>
> You may use Plot if you need a simple way to create a standard plot. The
> second method gives you more flexibility and access to the data source,
> e.g. in case you need to update them to react to some event in your
> application.
>
> Best,
> Pietro
>
>
>  
>
>
>     I note that AbstractDataSource has the advantange of saving the
>     metadata, which in 'selections' has information from tools such as mouse
>     position and selections. (I also understand that my second example can
>     be used for irregular grids.)
>
>     Also, if using the ArrayPlotData path, and building some tool from
>     BaseTool, is there any communication method between the tool and the
>     plot (similar to metadata in ImageData)? I saw the example tool that
>     prints event.x and event.y on normal_mouse_move, but did not see an
>     obvious communication if I want to use these values from the plot itself
>     (or a class calling the plot).
>
>     Thanks again,
>
>     Tiago
>     _______________________________________________
>     Enthought-Dev mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
>
>
> _______________________________________________
> 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