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

Don't recalcuate histogram if not necessary #282

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion napari_clusters_plotter/_Qt_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@
self.match_napari_layout()
self.xylim = None
self.last_xy_labels = None
self.last_datax = None
self.last_datay = None

super().__init__(self.fig)
self.mpl_connect("draw_event", self.on_draw)
Expand Down Expand Up @@ -590,7 +592,17 @@
norm = None
if log_scale:
norm = "log"
h, xedges, yedges = np.histogram2d(data_x, data_y, bins=bin_number)
if (

Check warning on line 595 in napari_clusters_plotter/_Qt_code.py

View check run for this annotation

Codecov / codecov/patch

napari_clusters_plotter/_Qt_code.py#L595

Added line #L595 was not covered by tests
self.histogram is not None
and np.array_equal(self.last_datax, data_x)
and np.array_equal(self.last_datay, data_y)
):
(h, xedges, yedges) = self.histogram

Check warning on line 600 in napari_clusters_plotter/_Qt_code.py

View check run for this annotation

Codecov / codecov/patch

napari_clusters_plotter/_Qt_code.py#L600

Added line #L600 was not covered by tests
else:
h, xedges, yedges = np.histogram2d(data_x, data_y, bins=bin_number)
self.last_datax = data_x
self.last_datay = data_y

Check warning on line 604 in napari_clusters_plotter/_Qt_code.py

View check run for this annotation

Codecov / codecov/patch

napari_clusters_plotter/_Qt_code.py#L602-L604

Added lines #L602 - L604 were not covered by tests

self.axes.imshow(
h.T,
extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]],
Expand Down
Loading