From 34854dbcff97f9199afce0a9492fb04ff63bccdd Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 8 Jan 2015 22:17:12 -0600 Subject: [PATCH 01/26] Add the ability for artists to display zdata in cursor --- lib/matplotlib/artist.py | 6 ++++++ lib/matplotlib/backend_bases.py | 6 ++++++ lib/matplotlib/image.py | 17 +++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 7fb492367f1d..3135074964ac 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -1020,6 +1020,12 @@ def get_setters(self): return [prop for prop, target in self._get_setters_and_targets()] + def get_zdata(self, event): + """ + Get the zdata for a given event, as a string message + """ + return '' + def is_alias(self, o): """ Return *True* if method object *o* is an alias for another diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 02f67136e7d0..d44efef875d2 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2800,6 +2800,12 @@ def mouse_move(self, event): except (ValueError, OverflowError): pass else: + ax = event.inaxes + artists = ax.artists + ax.images + ax.lines + artists = [a for a in artists if a.contains(event)[0]] + if artists: + artist = artists[np.argmax([a.zorder for a in artists])] + s += artist.get_zdata(event) if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) else: diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 2428147218bb..8a2a1d24d1cf 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -683,6 +683,23 @@ def get_extent(self): else: return (-0.5, numcols-0.5, -0.5, numrows-0.5) + def get_zdata(self, event): + """Get the zdata message for a given event""" + xmin, xmax, ymin, ymax = self.get_extent() + if self.origin == 'upper': + ymin, ymax = ymax, ymin + arr = self.get_array() + data_extent = mtransforms.Bbox([[ymin, xmin], [ymax, xmax]]) + array_extent = mtransforms.Bbox([[0, 0], arr.shape[:2]]) + trans = mtransforms.BboxTransformFrom(data_extent) +\ + mtransforms.BboxTransformTo(array_extent) + i, j = trans.transform_point([event.ydata, event.xdata]).astype(int) + z = arr[i, j] + if z.size > 1: + # Override default numpy formatting for this specific case. Bad idea? + z = ', '.join('{:0.3g}'.format(item) for item in z) + return 'z=%s' % z + class NonUniformImage(AxesImage): def __init__(self, ax, **kwargs): From 7e0d1ca59513bf5f1c18a7a244e7a0f3a6b34a10 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 8 Jan 2015 22:49:52 -0600 Subject: [PATCH 02/26] PEP8 fix --- lib/matplotlib/image.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 8a2a1d24d1cf..fbfd1c987bfd 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -693,7 +693,8 @@ def get_zdata(self, event): array_extent = mtransforms.Bbox([[0, 0], arr.shape[:2]]) trans = mtransforms.BboxTransformFrom(data_extent) +\ mtransforms.BboxTransformTo(array_extent) - i, j = trans.transform_point([event.ydata, event.xdata]).astype(int) + y, x = event.ydata, event.xdata + i, j = trans.transform_point([y, x]).astype(int) z = arr[i, j] if z.size > 1: # Override default numpy formatting for this specific case. Bad idea? From 97640dace8770ea15eb720b007ee9b46ff5ec1fe Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 10 Jan 2015 13:52:57 -0600 Subject: [PATCH 03/26] Another Pep8 fix --- lib/matplotlib/image.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index fbfd1c987bfd..b00c2e688f44 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -697,7 +697,8 @@ def get_zdata(self, event): i, j = trans.transform_point([y, x]).astype(int) z = arr[i, j] if z.size > 1: - # Override default numpy formatting for this specific case. Bad idea? + # Override default numpy formatting for this specific case. + # Bad idea? z = ', '.join('{:0.3g}'.format(item) for item in z) return 'z=%s' % z From 139d820cecc643fd7f56ed481a404c1691749124 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 10 Jan 2015 13:58:13 -0600 Subject: [PATCH 04/26] Pep8: fix trailing whitespace --- lib/matplotlib/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index b00c2e688f44..caaa426036ad 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -697,7 +697,7 @@ def get_zdata(self, event): i, j = trans.transform_point([y, x]).astype(int) z = arr[i, j] if z.size > 1: - # Override default numpy formatting for this specific case. + # Override default numpy formatting for this specific case. # Bad idea? z = ', '.join('{:0.3g}'.format(item) for item in z) return 'z=%s' % z From 17e42119a9aa0e4408b2f456a835e5c485868440 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 10 Jan 2015 14:30:37 -0600 Subject: [PATCH 05/26] Style update --- lib/matplotlib/image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index caaa426036ad..62c4495937c8 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -691,8 +691,8 @@ def get_zdata(self, event): arr = self.get_array() data_extent = mtransforms.Bbox([[ymin, xmin], [ymax, xmax]]) array_extent = mtransforms.Bbox([[0, 0], arr.shape[:2]]) - trans = mtransforms.BboxTransformFrom(data_extent) +\ - mtransforms.BboxTransformTo(array_extent) + trans = (mtransforms.BboxTransformFrom(data_extent) + + mtransforms.BboxTransformTo(array_extent)) y, x = event.ydata, event.xdata i, j = trans.transform_point([y, x]).astype(int) z = arr[i, j] From fcda62bd80eb15664baca4d02194ed52e0b374e0 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 09:48:55 -0600 Subject: [PATCH 06/26] Standardize the hit test and zordering --- lib/matplotlib/backend_bases.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index d44efef875d2..86ae144ed663 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -38,6 +38,7 @@ import warnings import time import io +from operator import itemgetter import numpy as np import matplotlib.cbook as cbook @@ -1694,15 +1695,9 @@ def onRemove(self, ev): canvas.mpl_connect('mouse_press_event',canvas.onRemove) """ - def sort_artists(artists): - # This depends on stable sort and artists returned - # from get_children in z order. - L = [(h.zorder, h) for h in artists] - L.sort() - return [h for zorder, h in L] - # Find the top artist under the cursor - under = sort_artists(self.figure.hitlist(ev)) + under = self.figure.hitlist(ev) + under.sort(key=itemgetter(0)) h = None if under: h = under[-1] @@ -2800,12 +2795,10 @@ def mouse_move(self, event): except (ValueError, OverflowError): pass else: - ax = event.inaxes - artists = ax.artists + ax.images + ax.lines - artists = [a for a in artists if a.contains(event)[0]] + artists = self.figure.hitlist(event) + artists.sort(key=itemgetter(0)) if artists: - artist = artists[np.argmax([a.zorder for a in artists])] - s += artist.get_zdata(event) + s += artists[-1].get_zdata(event) if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) else: From 8ea95048d1720eda25775ad260ebbc11bc9042be Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 09:52:00 -0600 Subject: [PATCH 07/26] Fix the artist sorting behaviour --- lib/matplotlib/backend_bases.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 86ae144ed663..5002f9e3c37b 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -38,7 +38,6 @@ import warnings import time import io -from operator import itemgetter import numpy as np import matplotlib.cbook as cbook @@ -1697,7 +1696,7 @@ def onRemove(self, ev): """ # Find the top artist under the cursor under = self.figure.hitlist(ev) - under.sort(key=itemgetter(0)) + under.sort(key=key=lambda x: x.zorder) h = None if under: h = under[-1] @@ -2796,7 +2795,7 @@ def mouse_move(self, event): pass else: artists = self.figure.hitlist(event) - artists.sort(key=itemgetter(0)) + artists.sort(key=lambda x: x.zorder) if artists: s += artists[-1].get_zdata(event) if len(self.mode): From 02456b82fd2cac4e28948f17237427e25d342900 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 09:53:34 -0600 Subject: [PATCH 08/26] Fix syntax error --- lib/matplotlib/backend_bases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 5002f9e3c37b..b0555afd1291 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1696,7 +1696,7 @@ def onRemove(self, ev): """ # Find the top artist under the cursor under = self.figure.hitlist(ev) - under.sort(key=key=lambda x: x.zorder) + under.sort(key=lambda x: x.zorder) h = None if under: h = under[-1] From 641304c0d23e2f90e5732b5087f2c982648fc225 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 10:02:39 -0600 Subject: [PATCH 09/26] Specify hitlist on axes instead of figure --- lib/matplotlib/backend_bases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index b0555afd1291..1239aaf6de33 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2794,7 +2794,7 @@ def mouse_move(self, event): except (ValueError, OverflowError): pass else: - artists = self.figure.hitlist(event) + artists = event.inaxes.hitlist(event) artists.sort(key=lambda x: x.zorder) if artists: s += artists[-1].get_zdata(event) From 3f20d3a957a381c419849caf23d64b435081c7db Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 10:28:11 -0600 Subject: [PATCH 10/26] Put get_zdata on the correct class --- lib/matplotlib/artist.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 3135074964ac..e8ec28bb064c 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -903,6 +903,12 @@ def matchfunc(x): artists.append(self) return artists + def get_zdata(self, event): + """ + Get the zdata for a given event, as a string message + """ + return '' + class ArtistInspector(object): """ @@ -1020,12 +1026,6 @@ def get_setters(self): return [prop for prop, target in self._get_setters_and_targets()] - def get_zdata(self, event): - """ - Get the zdata for a given event, as a string message - """ - return '' - def is_alias(self, o): """ Return *True* if method object *o* is an alias for another From 58501502893169cee7773932b9d6c6ad4454f640 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 10:43:36 -0600 Subject: [PATCH 11/26] Ignore the axes patch --- lib/matplotlib/backend_bases.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 1239aaf6de33..b4d217e475a3 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2795,6 +2795,8 @@ def mouse_move(self, event): pass else: artists = event.inaxes.hitlist(event) + if event.inaxes.patch in artists: + artists.remove(event.inaxes.patch) artists.sort(key=lambda x: x.zorder) if artists: s += artists[-1].get_zdata(event) From 88b56be198c4c47fc5976c17d105d91b3ff6e53c Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 11:12:25 -0600 Subject: [PATCH 12/26] Create new function to format zdata --- lib/matplotlib/artist.py | 15 +++++++++++++++ lib/matplotlib/image.py | 6 +----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index e8ec28bb064c..acf9558d74b1 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -909,6 +909,21 @@ def get_zdata(self, event): """ return '' + def format_zdata(self, z): + """ + Return *z* string formatted. + """ + try: + is_int = isinstance(z[0], int) + except (TypeError, IndexError): + is_int = isinstance(z, int) + z = [z] + if is_int: + z = ', '.join('{:0}'.format(item) for item in z) + else: + z = ', '.join('{:0.3g}'.format(item) for item in z) + return z + class ArtistInspector(object): """ diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 62c4495937c8..2a16f7bbcdec 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -696,11 +696,7 @@ def get_zdata(self, event): y, x = event.ydata, event.xdata i, j = trans.transform_point([y, x]).astype(int) z = arr[i, j] - if z.size > 1: - # Override default numpy formatting for this specific case. - # Bad idea? - z = ', '.join('{:0.3g}'.format(item) for item in z) - return 'z=%s' % z + return 'z=%s' % self.format_zdata(z) class NonUniformImage(AxesImage): From aece695327ec287043d6f1a6aad53e68885798de Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 11:13:58 -0600 Subject: [PATCH 13/26] Clean up string formatting --- lib/matplotlib/artist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index acf9558d74b1..16133ab82ba0 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -919,7 +919,7 @@ def format_zdata(self, z): is_int = isinstance(z, int) z = [z] if is_int: - z = ', '.join('{:0}'.format(item) for item in z) + z = ', '.join(item for item in z) else: z = ', '.join('{:0.3g}'.format(item) for item in z) return z From 07745c8fe785897db3c03c7fa5021394dcde0833 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 21:19:00 -0600 Subject: [PATCH 14/26] Add a whats new blurb. --- doc/users/whats_new/2015-01-19_cursor_zdata.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/users/whats_new/2015-01-19_cursor_zdata.rst diff --git a/doc/users/whats_new/2015-01-19_cursor_zdata.rst b/doc/users/whats_new/2015-01-19_cursor_zdata.rst new file mode 100644 index 000000000000..a3be59e26ed6 --- /dev/null +++ b/doc/users/whats_new/2015-01-19_cursor_zdata.rst @@ -0,0 +1,6 @@ +Allow Artists to Display ZData in Cursor +---------------------------------------- + +Adds `get_zdata` and `format_zdata` methods to artists +which can be used to add zdata to the cursor display +in the status bar. Also adds an implementation for Images. From 76263943b25664336b15870c56511356b48ba2fe Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 20 Feb 2015 21:44:28 -0600 Subject: [PATCH 15/26] Add a test for image cursor data --- lib/matplotlib/tests/test_image.py | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 89338d33fdad..4739170561f9 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -158,6 +158,39 @@ def test_imsave_color_alpha(): assert_array_equal(data, arr_buf) + +@cleanup +def test_cursor_data(): + from matplotlib.backend_bases import MouseEvent + + fig, ax = plt.subplots() + im = ax.imshow(np.arange(100).reshape(10, 10), origin='upper') + + x, y = 4, 4 + xdisp, ydisp = ax.transData.transform_point([x, y]) + + event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) + assert im.get_zdata(event) == 44 + + ax.clear() + im = ax.imshow(np.arange(100).reshape(10, 10), origin='lower') + + x, y = 4, 4 + xdisp, ydisp = ax.transData.transform_point([x, y]) + + event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) + assert im.get_zdata(event) == 44 + + fig, ax = plt.subplots() + im = ax.imshow(np.arange(100).reshape(10, 10), extent=[0, 0.5, 0, 0.5]) + + x, y = 0.25, 0.25 + xdisp, ydisp = ax.transData.transform_point([x, y]) + + event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) + assert im.get_zdata(event) == 55 + + @image_comparison(baseline_images=['image_clip']) def test_image_clip(): from math import pi From 7b0b6b1f5536a508df08c2f741f5ec3c8f4cda11 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 20 Feb 2015 21:44:51 -0600 Subject: [PATCH 16/26] Rename to get_pixel_data and return raw data --- lib/matplotlib/artist.py | 20 ++++++++++---------- lib/matplotlib/backend_bases.py | 4 +++- lib/matplotlib/image.py | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 16133ab82ba0..383c066f2b19 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -903,26 +903,26 @@ def matchfunc(x): artists.append(self) return artists - def get_zdata(self, event): + def get_pixel_data(self, event): """ - Get the zdata for a given event, as a string message + Get the pixel data for a given event. """ return '' - def format_zdata(self, z): + def format_pixel_data(self, data): """ - Return *z* string formatted. + Return *pixel data* string formatted. """ try: - is_int = isinstance(z[0], int) + is_int = isinstance(data[0], int) except (TypeError, IndexError): - is_int = isinstance(z, int) - z = [z] + is_int = isinstance(data, int) + data = [data] if is_int: - z = ', '.join(item for item in z) + data = ', '.join(item for item in data) else: - z = ', '.join('{:0.3g}'.format(item) for item in z) - return z + data = ', '.join('{:0.3g}'.format(item) for item in data) + return data class ArtistInspector(object): diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index b4d217e475a3..56c2d8be86bb 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2799,7 +2799,9 @@ def mouse_move(self, event): artists.remove(event.inaxes.patch) artists.sort(key=lambda x: x.zorder) if artists: - s += artists[-1].get_zdata(event) + a = artists[-1] + data = a.get_cursor_data(event) + s += 'data= %s' % a.format_cursor_data(data) if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) else: diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 2a16f7bbcdec..3c5ee5e1bce3 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -696,7 +696,7 @@ def get_zdata(self, event): y, x = event.ydata, event.xdata i, j = trans.transform_point([y, x]).astype(int) z = arr[i, j] - return 'z=%s' % self.format_zdata(z) + return z class NonUniformImage(AxesImage): From f5ff73f57fd25533657596c66cd02f24c8370832 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 20 Feb 2015 21:45:25 -0600 Subject: [PATCH 17/26] Update the whats new --- doc/users/whats_new/2015-01-19_cursor_pixel_data.rst | 6 ++++++ doc/users/whats_new/2015-01-19_cursor_zdata.rst | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 doc/users/whats_new/2015-01-19_cursor_pixel_data.rst delete mode 100644 doc/users/whats_new/2015-01-19_cursor_zdata.rst diff --git a/doc/users/whats_new/2015-01-19_cursor_pixel_data.rst b/doc/users/whats_new/2015-01-19_cursor_pixel_data.rst new file mode 100644 index 000000000000..4490e9df35e4 --- /dev/null +++ b/doc/users/whats_new/2015-01-19_cursor_pixel_data.rst @@ -0,0 +1,6 @@ +Allow Artists to Display Pixel Data in Cursor +--------------------------------------------- + +Adds `get_pixel_data` and `format_pixel_data` methods to artists +which can be used to add zdata to the cursor display +in the status bar. Also adds an implementation for Images. diff --git a/doc/users/whats_new/2015-01-19_cursor_zdata.rst b/doc/users/whats_new/2015-01-19_cursor_zdata.rst deleted file mode 100644 index a3be59e26ed6..000000000000 --- a/doc/users/whats_new/2015-01-19_cursor_zdata.rst +++ /dev/null @@ -1,6 +0,0 @@ -Allow Artists to Display ZData in Cursor ----------------------------------------- - -Adds `get_zdata` and `format_zdata` methods to artists -which can be used to add zdata to the cursor display -in the status bar. Also adds an implementation for Images. From ea565c648ec66ccd492f0fc6f66f9fafb0f3cbb4 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 20 Feb 2015 21:52:56 -0600 Subject: [PATCH 18/26] Fix name of method --- lib/matplotlib/image.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 3c5ee5e1bce3..5dd6811d915e 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -683,8 +683,8 @@ def get_extent(self): else: return (-0.5, numcols-0.5, -0.5, numrows-0.5) - def get_zdata(self, event): - """Get the zdata message for a given event""" + def get_pixel_data(self, event): + """Get the pixel data for a given event""" xmin, xmax, ymin, ymax = self.get_extent() if self.origin == 'upper': ymin, ymax = ymax, ymin @@ -695,8 +695,7 @@ def get_zdata(self, event): mtransforms.BboxTransformTo(array_extent)) y, x = event.ydata, event.xdata i, j = trans.transform_point([y, x]).astype(int) - z = arr[i, j] - return z + return arr[i, j] class NonUniformImage(AxesImage): From 1429206fa211e71153bdc651aad25adcacb66175 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Fri, 20 Feb 2015 21:53:22 -0600 Subject: [PATCH 19/26] Fix default pixel data and handle no pixel data --- lib/matplotlib/artist.py | 2 +- lib/matplotlib/backend_bases.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 383c066f2b19..fa7f509dda97 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -907,7 +907,7 @@ def get_pixel_data(self, event): """ Get the pixel data for a given event. """ - return '' + return None def format_pixel_data(self, data): """ diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 56c2d8be86bb..9c6abe96ce93 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2800,8 +2800,9 @@ def mouse_move(self, event): artists.sort(key=lambda x: x.zorder) if artists: a = artists[-1] - data = a.get_cursor_data(event) - s += 'data= %s' % a.format_cursor_data(data) + data = a.get_pixel_data(event) + if data is not None: + s += ' data=%s' % a.format_pixel_data(data) if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) else: From e62b0e34f5dca0f1552f6a7c254feffce74de4ae Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 21 Feb 2015 12:10:03 -0600 Subject: [PATCH 20/26] Update test for new method name --- lib/matplotlib/tests/test_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 4739170561f9..995cd3006b28 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -170,7 +170,7 @@ def test_cursor_data(): xdisp, ydisp = ax.transData.transform_point([x, y]) event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) - assert im.get_zdata(event) == 44 + assert im.get_pixel_data(event) == 44 ax.clear() im = ax.imshow(np.arange(100).reshape(10, 10), origin='lower') @@ -179,7 +179,7 @@ def test_cursor_data(): xdisp, ydisp = ax.transData.transform_point([x, y]) event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) - assert im.get_zdata(event) == 44 + assert im.get_pixel_data(event) == 44 fig, ax = plt.subplots() im = ax.imshow(np.arange(100).reshape(10, 10), extent=[0, 0.5, 0, 0.5]) @@ -188,7 +188,7 @@ def test_cursor_data(): xdisp, ydisp = ax.transData.transform_point([x, y]) event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) - assert im.get_zdata(event) == 55 + assert im.get_pixel_data(event) == 55 @image_comparison(baseline_images=['image_clip']) From 34b4df440753d2e0cb0539cd1c911271a9691564 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 21 Feb 2015 12:10:04 -0600 Subject: [PATCH 21/26] Simplify transform --- lib/matplotlib/image.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 5dd6811d915e..9fc049ffb6e8 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -691,8 +691,8 @@ def get_pixel_data(self, event): arr = self.get_array() data_extent = mtransforms.Bbox([[ymin, xmin], [ymax, xmax]]) array_extent = mtransforms.Bbox([[0, 0], arr.shape[:2]]) - trans = (mtransforms.BboxTransformFrom(data_extent) + - mtransforms.BboxTransformTo(array_extent)) + trans = mtransforms. BboxTransform(boxin=data_extent, + boxout=array_extent) y, x = event.ydata, event.xdata i, j = trans.transform_point([y, x]).astype(int) return arr[i, j] From 8f266a1ecb39ea273d0a97d1dc7c0c49c9edabe0 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 21 Feb 2015 12:12:43 -0600 Subject: [PATCH 22/26] Update display --- lib/matplotlib/backend_bases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 9c6abe96ce93..535f3aedb5ef 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2802,7 +2802,7 @@ def mouse_move(self, event): a = artists[-1] data = a.get_pixel_data(event) if data is not None: - s += ' data=%s' % a.format_pixel_data(data) + s += ' [%s]' % a.format_pixel_data(data) if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) else: From 70983ff94df5701e66ea337b35e4468b0f13eb2a Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 8 Mar 2015 14:22:07 -0500 Subject: [PATCH 23/26] Simplify format_pixel_data --- lib/matplotlib/artist.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index fa7f509dda97..0b8d2c30f94d 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -914,15 +914,10 @@ def format_pixel_data(self, data): Return *pixel data* string formatted. """ try: - is_int = isinstance(data[0], int) + data[0] except (TypeError, IndexError): - is_int = isinstance(data, int) data = [data] - if is_int: - data = ', '.join(item for item in data) - else: - data = ', '.join('{:0.3g}'.format(item) for item in data) - return data + return ', '.join('{:0.3g}'.format(item) for item in data) class ArtistInspector(object): From cd0e52b600f7df82d0d36974b2dbebdb20d808c6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 8 Mar 2015 14:56:01 -0500 Subject: [PATCH 24/26] Update name to cursor_data --- lib/matplotlib/artist.py | 8 ++++---- lib/matplotlib/backend_bases.py | 4 ++-- lib/matplotlib/image.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 0b8d2c30f94d..57fdf1bb673a 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -903,15 +903,15 @@ def matchfunc(x): artists.append(self) return artists - def get_pixel_data(self, event): + def get_cursor_data(self, event): """ - Get the pixel data for a given event. + Get the cursor data for a given event. """ return None - def format_pixel_data(self, data): + def format_cursor_data(self, data): """ - Return *pixel data* string formatted. + Return *cursor data* string formatted. """ try: data[0] diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 535f3aedb5ef..f525c936f908 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2800,9 +2800,9 @@ def mouse_move(self, event): artists.sort(key=lambda x: x.zorder) if artists: a = artists[-1] - data = a.get_pixel_data(event) + data = a.get_cursor_data(event) if data is not None: - s += ' [%s]' % a.format_pixel_data(data) + s += ' [%s]' % a.format_cursor_data(data) if len(self.mode): self.set_message('%s, %s' % (self.mode, s)) else: diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 9fc049ffb6e8..189091d95eb9 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -683,8 +683,8 @@ def get_extent(self): else: return (-0.5, numcols-0.5, -0.5, numrows-0.5) - def get_pixel_data(self, event): - """Get the pixel data for a given event""" + def get_cursor_data(self, event): + """Get the cursor data for a given event""" xmin, xmax, ymin, ymax = self.get_extent() if self.origin == 'upper': ymin, ymax = ymax, ymin From 8ce3a6ff5bd0571441334ef674fa9257f512eab2 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 9 Mar 2015 21:37:14 -0500 Subject: [PATCH 25/26] Move artist sort to within if block --- lib/matplotlib/backend_bases.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index f525c936f908..a53a084877e6 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2797,8 +2797,9 @@ def mouse_move(self, event): artists = event.inaxes.hitlist(event) if event.inaxes.patch in artists: artists.remove(event.inaxes.patch) - artists.sort(key=lambda x: x.zorder) + if artists: + artists.sort(key=lambda x: x.zorder) a = artists[-1] data = a.get_cursor_data(event) if data is not None: From bac8dffd4f071ac0ee8bdf5cd7327eed2b01d6e8 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 16 Mar 2015 21:56:48 -0500 Subject: [PATCH 26/26] Fix method name in cursor_test --- lib/matplotlib/tests/test_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 995cd3006b28..c1e0ec7f9e82 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -170,7 +170,7 @@ def test_cursor_data(): xdisp, ydisp = ax.transData.transform_point([x, y]) event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) - assert im.get_pixel_data(event) == 44 + assert im.get_cursor_data(event) == 44 ax.clear() im = ax.imshow(np.arange(100).reshape(10, 10), origin='lower') @@ -179,7 +179,7 @@ def test_cursor_data(): xdisp, ydisp = ax.transData.transform_point([x, y]) event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) - assert im.get_pixel_data(event) == 44 + assert im.get_cursor_data(event) == 44 fig, ax = plt.subplots() im = ax.imshow(np.arange(100).reshape(10, 10), extent=[0, 0.5, 0, 0.5]) @@ -188,7 +188,7 @@ def test_cursor_data(): xdisp, ydisp = ax.transData.transform_point([x, y]) event = MouseEvent('motion_notify_event', fig.canvas, xdisp, ydisp) - assert im.get_pixel_data(event) == 55 + assert im.get_cursor_data(event) == 55 @image_comparison(baseline_images=['image_clip']) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy