Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line handling of nans #67

Closed
EricThomson opened this issue Dec 13, 2022 · 7 comments
Closed

Line handling of nans #67

EricThomson opened this issue Dec 13, 2022 · 7 comments

Comments

@EricThomson
Copy link
Contributor

EricThomson commented Dec 13, 2022

When data contains nans rendering doesn't work for line objects. Images work (i.e., the nans just show up as zeros).

xs = np.linspace(0, 30, 500)
ys = np.sin(xs)
ys[30:50] = np.nan
data1 = np.dstack([xs, ys])[0]

plot_l = Plot()
plot_l.line(data=data1, size=2, cmap="jet")
plot_l.show()

Compare to following which shows up fine (line renders except the nans which are just blank -- obviously could be handled differently this is just one option):

import matplotlib.pyplot as plt
plt.plot(xs, ys)

In practice this comes up frequently as the caiman coordinates have nans in them fairly often (right now I just filter out those nan-containing rows).

@kushalkolar
Copy link
Member

Yes I see, I encountered this issue with the HistogramGraphic previously and fixed it in #28

We could just implement it in the base Graphic when data are converted to float32, do you want to do your first PR? :D https://github.com/kushalkolar/fastplotlib/blob/master/fastplotlib/graphics/_base.py#L19

@EricThomson
Copy link
Contributor Author

Seems like a good one for start with for sure :) Might take me a little while to get to it (weekend likely).

@kushalkolar
Copy link
Member

thinking about this more, for lines we don't want to show it as zeros though becuase this will actually move the position of the line vertex, maybe we can set the alpha value for the color at those points to zero

@EricThomson
Copy link
Contributor Author

Yes the zero strategy won’t work for lines. Either need to interpolate or make the relevant bits disappear. For the latter, could split into multiple lines or the alpha trick sound good. Having to track multiple separate line objects would probably be a pain!

@kushalkolar
Copy link
Member

splitting into multiple lines would be a major pain, definitely try the alpha method!

@kushalkolar
Copy link
Member

I made a PR in pygfx which should fix this, it was a camera issue because autoscaling isn't possible when the bbox is nan:

pygfx/pygfx#540

@kushalkolar
Copy link
Member

fixed in pygfx/pygfx#540

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants