pyqtgraph icon indicating copy to clipboard operation
pyqtgraph copied to clipboard

Adding support for connect PlotItem connect vector during view clippng and downsampling

Open tblum opened this issue 1 year ago • 4 comments

When using the connect vector argument to plot (PlotItem) one can not use ClitToView or Downsampling. Using them will cause an Exception (ValueError):

E.g running this code and activating "clip to view" or downsampling via right click menu:

import numpy as np
import pyqtgraph as pg

x = np.linspace(0.0, 7.0, num=10000)
x = np.concatenate((x[:3000], x[7000:]))
y = np.sin(x)
c = np.ones(len(x), dtype=bool)
c[2999] = False
pg.plot(x,y, connect=c)

if __name__ == '__main__':
    pg.exec()

This PR "fixes" that. Clipping works as expected. Down-sampling will no linger cast exception. Don't know if it is the best strategy for down-sampling the connect vector. But I didn't want to make the calculations too expensive.

Best regards Troels Blum

tblum avatar Oct 08 '24 12:10 tblum

I also create a patch for version 13.7 since that is the version installed by pip (and that I am using) Don't know if that is useful? pyqtgraph_connect.patch

tblum avatar Oct 08 '24 12:10 tblum

Hi @tblum

Thanks for this PR, this change LGTM.

Can you add a test in test_PlotDataItem.py that will demonstrate this functionality? There is a test_clipping function there already, maybe would benefit from parameterizing x, y and connect arguments. Let mek now if you would need some guidance.

Thanks for the PR!

j9ac9k avatar Oct 13 '24 06:10 j9ac9k

Updated the doc-string and added a test based on the example I posted.

tblum avatar Oct 14 '24 13:10 tblum

@j9ac9k Am I missing something, or is this good to go?

tblum avatar Oct 28 '24 08:10 tblum

Hi @tblum

Thanks for the PR, sorry this has taken me so long to get to it. This LGTM, merging!

j9ac9k avatar Mar 24 '25 19:03 j9ac9k