For an application I am developing, I need to call ax.scatter then change the colors of the points after the fact. However, if the input x/y values contain NaN values, then setting the colors after the fact doesn't work properly. The following example:
The top right point should be all yellow. However it isn't, because in the scatter call, invalid values are removed, so when I try and set the colors with set_array, the color values are offset from the x/y values. In the final case, things work since the 'bad' values are masked from neither the offsets nor the colors.
Is there a way to achieve something along the lines of the middle example (setting the colors after the fact)
This is because we create the initial artist and strip out any points that have nan in them. The new colors will then be offset from where you think they should be.
attn @efiring as you have been working around this code recently.
I think that adding the requested functionality will require writing a subclass of PathCollection that can keep track of the original inputs, and can repeat the mask- and nan-filtering operation every time a relevant property is updated.
Do we actually need to filter out the nans (except for backcompatibility considerations)? Aren't the renderers supposed to be able to handle nan data to start with anyways?
Good question; maybe they all can. If so, taking advantage of that would require some substantial changes, I think, because we support masked arrays, and use them internally. Going 100% with nans for missing values implies always using floating point, and switching from .max to .nanmax etc.
Activity
tacaswell commented on Feb 5, 2018
This is because we create the initial artist and strip out any points that have nan in them. The new colors will then be offset from where you think they should be.
attn @efiring as you have been working around this code recently.
efiring commented on Feb 5, 2018
I think that adding the requested functionality will require writing a subclass of PathCollection that can keep track of the original inputs, and can repeat the mask- and nan-filtering operation every time a relevant property is updated.
anntzer commented on Feb 6, 2018
Do we actually need to filter out the nans (except for backcompatibility considerations)? Aren't the renderers supposed to be able to handle nan data to start with anyways?
efiring commented on Feb 7, 2018
Good question; maybe they all can. If so, taking advantage of that would require some substantial changes, I think, because we support masked arrays, and use them internally. Going 100% with nans for missing values implies always using floating point, and switching from .max to .nanmax etc.
Alternative approach; addresses matplotlib#10381
Alternative approach; addresses matplotlib#10381
Alternative approach; addresses matplotlib#10381
Alternative approach; addresses matplotlib#10381
efiring commented on Apr 15, 2019
I think this is closed by #12422. If not, please reopen.