Skip to content

Commit

Permalink
don't recalculate histograms if data hasnt changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
thorstenwagner committed Dec 7, 2023
1 parent 37c2f79 commit f80e5c8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 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 @@ def __init__(self, parent=None, width=7, height=4, manual_clustering_method=None
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,10 +592,14 @@ def make_2d_histogram(
norm = None
if log_scale:
norm = "log"
if self.histogram is not None:
if self.histogram is not None and np.array_equal(self.last_datax, data_x) and np.array_equal(self.last_datay,

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
data_y):
(h, xedges, yedges) = self.histogram

Check warning on line 597 in napari_clusters_plotter/_Qt_code.py

View check run for this annotation

Codecov / codecov/patch

napari_clusters_plotter/_Qt_code.py#L597

Added line #L597 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 601 in napari_clusters_plotter/_Qt_code.py

View check run for this annotation

Codecov / codecov/patch

napari_clusters_plotter/_Qt_code.py#L599-L601

Added lines #L599 - L601 were not covered by tests

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

0 comments on commit f80e5c8

Please sign in to comment.