Common metadata

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

Common metadata

Jordan Ilott

I'm quite new to Chaco and Python and I'm having trouble connecting the metadata between two plots. In my application, I need to be able to select a point in one scatter plot and observe that selection in several others. I think this concept is typically referred to as brushing. In the somewhat trivial case, I can simply make the index of two scatter plots equal: scatterPlot1.index=scatterPlot2.index . This works, however, if the index to be plotted is not the same, then it is not helpful. Instead, I would rather do: scatterPlot1.index.metadata=scatterPlot2.index.metadata . For some reason (that is probably obvious to more experienced Cacho and Python developers) this technique does not work. Can anyone offer some guidance on this?

Thanks

Jordan


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

Re: Common metadata

Robert Kern
On Tue, Feb 19, 2013 at 4:30 AM, Jordan Ilott <[hidden email]> wrote:

> I'm quite new to Chaco and Python and I'm having trouble connecting the
> metadata between two plots. In my application, I need to be able to select a
> point in one scatter plot and observe that selection in several others. I
> think this concept is typically referred to as brushing. In the somewhat
> trivial case, I can simply make the index of two scatter plots equal:
> scatterPlot1.index=scatterPlot2.index . This works, however, if the index to
> be plotted is not the same, then it is not helpful. Instead, I would rather
> do: scatterPlot1.index.metadata=scatterPlot2.index.metadata . For some
> reason (that is probably obvious to more experienced Cacho and Python
> developers) this technique does not work. Can anyone offer some guidance on
> this?

Chaco is built on top of Traits, which provides the notification
functionality that lets the tools modify the metadata dictionary and
the renderers listen to those changes. In order to listen to
modifications of a dict, we replace dicts on assignment with an
instrumented dict type, thereby copying the data into a new object:

  scatterPlot1.index.metadata = scatterPlot2.index.metadata
  assert scatterPlot1.index.metadata is not scatterPlot2.index.metadata

One approach is to just use
`scatterPlot1.index.metadata['selections']` in the other plot. You can
listen to the `scatterPlot1.index.metadata_changed` event to know when
to update the other plot. Here is an example:

  https://github.com/enthought/chaco/blob/master/examples/demo/xray_plot.py

It seems like you want to use existing renderers that use the
'selections' metadata on the other plot, though. You will want to
listen to the `metadata_changed` event and then copy over the
'selections' list to the other metadata. Here is an example:

  https://github.com/enthought/chaco/blob/master/examples/demo/financial/correlations.py

--
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: Common metadata

Jordan Ilott-2

Thanks for your help. When I try to implement something similar to the financial example, I find that the event is a Boolean value in the event listener. In my test example, I'm using a scatter plot renderer rather than a line renderer. Can you suggest where I may be going wrong?

On Feb 19, 2013 4:06 AM, "Robert Kern" <[hidden email]> wrote:
On Tue, Feb 19, 2013 at 4:30 AM, Jordan Ilott <[hidden email]> wrote:
> I'm quite new to Chaco and Python and I'm having trouble connecting the
> metadata between two plots. In my application, I need to be able to select a
> point in one scatter plot and observe that selection in several others. I
> think this concept is typically referred to as brushing. In the somewhat
> trivial case, I can simply make the index of two scatter plots equal:
> scatterPlot1.index=scatterPlot2.index . This works, however, if the index to
> be plotted is not the same, then it is not helpful. Instead, I would rather
> do: scatterPlot1.index.metadata=scatterPlot2.index.metadata . For some
> reason (that is probably obvious to more experienced Cacho and Python
> developers) this technique does not work. Can anyone offer some guidance on
> this?

Chaco is built on top of Traits, which provides the notification
functionality that lets the tools modify the metadata dictionary and
the renderers listen to those changes. In order to listen to
modifications of a dict, we replace dicts on assignment with an
instrumented dict type, thereby copying the data into a new object:

  scatterPlot1.index.metadata = scatterPlot2.index.metadata
  assert scatterPlot1.index.metadata is not scatterPlot2.index.metadata

One approach is to just use
`scatterPlot1.index.metadata['selections']` in the other plot. You can
listen to the `scatterPlot1.index.metadata_changed` event to know when
to update the other plot. Here is an example:

  https://github.com/enthought/chaco/blob/master/examples/demo/xray_plot.py

It seems like you want to use existing renderers that use the
'selections' metadata on the other plot, though. You will want to
listen to the `metadata_changed` event and then copy over the
'selections' list to the other metadata. Here is an example:

  https://github.com/enthought/chaco/blob/master/examples/demo/financial/correlations.py

--
Robert Kern
Enthought
_______________________________________________
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: Common metadata

Robert Kern
On Tue, Feb 19, 2013 at 9:55 PM, Jordan Ilott <[hidden email]> wrote:
> Thanks for your help. When I try to implement something similar to the
> financial example, I find that the event is a Boolean value in the event
> listener. In my test example, I'm using a scatter plot renderer rather than
> a line renderer. Can you suggest where I may be going wrong?

I'm sorry, but you've run into a rather confusing area where the
original author decided to do inconsistent things and depend on that
inconsistency in a public example. Ignore the contents of the event
and just look at the metadata dict itself to copy the information.

--
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: Common metadata

Jordan Ilott-2

Great, thanks for clarifying that for me. I think I have enough of an understanding to continue now.

On Feb 19, 2013 4:10 PM, "Robert Kern" <[hidden email]> wrote:
On Tue, Feb 19, 2013 at 9:55 PM, Jordan Ilott <[hidden email]> wrote:
> Thanks for your help. When I try to implement something similar to the
> financial example, I find that the event is a Boolean value in the event
> listener. In my test example, I'm using a scatter plot renderer rather than
> a line renderer. Can you suggest where I may be going wrong?

I'm sorry, but you've run into a rather confusing area where the
original author decided to do inconsistent things and depend on that
inconsistency in a public example. Ignore the contents of the event
and just look at the metadata dict itself to copy the information.

--
Robert Kern
Enthought
_______________________________________________
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: Common metadata

Jordan Ilott-2
In reply to this post by Robert Kern

Can you elaborate on this inconsistency? I'm going to have as many as 324 plots sharing see selection data, knowing where the event originated would help.

On Feb 19, 2013 4:10 PM, "Robert Kern" <[hidden email]> wrote:
On Tue, Feb 19, 2013 at 9:55 PM, Jordan Ilott <[hidden email]> wrote:
> Thanks for your help. When I try to implement something similar to the
> financial example, I find that the event is a Boolean value in the event
> listener. In my test example, I'm using a scatter plot renderer rather than
> a line renderer. Can you suggest where I may be going wrong?

I'm sorry, but you've run into a rather confusing area where the
original author decided to do inconsistent things and depend on that
inconsistency in a public example. Ignore the contents of the event
and just look at the metadata dict itself to copy the information.

--
Robert Kern
Enthought
_______________________________________________
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: Common metadata

Robert Kern
On Mon, Feb 25, 2013 at 2:52 PM, Jordan Ilott <[hidden email]> wrote:
> Can you elaborate on this inconsistency? I'm going to have as many as 324
> plots sharing see selection data, knowing where the event originated would
> help.

Event traits are "write-only" traits that are used to set up some
kinds of notifications. They aren't persistent attributes, but you can
hook up trait change handlers to get called whenever someone assigns
anything to them. The object that gets assigned is up to the
architect, but it is typically just "True" if all you want to do is
communicated that some event happened. This is what the
`metadata_changed` Event is supposed to accept.

  https://github.com/enthought/chaco/blob/master/chaco/array_data_source.py#L268

The author of the RangeSelection tool decided to pass extra information:

  https://github.com/enthought/chaco/blob/master/chaco/tools/range_selection.py#L581

And the financial plot example decided to rely on that detail. Like
the financial example, you could try to detect when you are given this
extra data instead of just True.

  https://github.com/enthought/chaco/blob/master/examples/demo/financial/correlations.py#L129

But you don't really have to. You can just take that you received the
event at all as notification that the metadata changed and look at the
metadata. You may be updating a bit more frequently as
non-RangeSelection metadata may get changed too, but that's usually
okay.

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