Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56a5cc9

Browse files
committed
Create a hidden colorbar on-the-fly to format imshow cursor data.
... if no colorbar exists yet.
1 parent3b37b08 commit56a5cc9

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Improved formatting of image values under cursor when a colorbar is present
22
```````````````````````````````````````````````````````````````````````````
33

4-
When a colorbar is present, its formatter is now used to format the image
5-
values under the mouse cursor in the status bar. For example, for an image
6-
displaying the values 10,000 and 10,001, the statusbar will now (using default
7-
settings) display the values as ``0.0+1e4`` and ``1.0+1e4`` (or ``10000.0``
8-
and ``10001.0`` if the offset-text is disabled on the colorbar), whereas both
9-
values were previously displayed as ``1e+04``.
4+
To format image values under the mouse cursor into the status bar, we now
5+
use the image's colorbar formatter (creating a hidden one on-the-fly if
6+
necessary). For example, for an image displaying the values 10,000 and
7+
10,001, the statusbar will now (using default settings) display the values as
8+
``0.0+1e4`` and ``1.0+1e4`` (or ``10000.0`` and ``10001.0`` if the offset-text
9+
is disabled on colorbars), whereas both values were previously displayed as
10+
``1e+04``.

‎lib/matplotlib/image.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,17 @@ def get_cursor_data(self, event):
907907
returnarr[i,j]
908908

909909
defformat_cursor_data(self,data):
910-
ifself.colorbar:
911-
return ("["
912-
+cbook.strip_math(self.colorbar.formatter(data))
913-
+cbook.strip_math(self.colorbar.formatter.get_offset())
914-
+"]")
915-
else:
916-
returnsuper().format_cursor_data(data)
910+
ifnotself.colorbar:
911+
frommatplotlib.figureimportFigure
912+
fig=Figure()
913+
ax=fig.subplots()
914+
self.colorbar=fig.colorbar(self,cax=ax)
915+
# This will call the locator and call set_locs() on the formatter.
916+
list(ax.yaxis.iter_ticks())
917+
return ("["
918+
+cbook.strip_math(self.colorbar.formatter(data))
919+
+cbook.strip_math(self.colorbar.formatter.get_offset())
920+
+"]")
917921

918922

919923
classNonUniformImage(AxesImage):

‎lib/matplotlib/tests/test_image.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,6 @@ def test_format_cursor_data():
270270

271271
xdisp,ydisp=ax.transData.transform_point([0,0])
272272
event=MouseEvent('motion_notify_event',fig.canvas,xdisp,ydisp)
273-
assertim.get_cursor_data(event)==10000
274-
assertim.format_cursor_data(im.get_cursor_data(event))=="[1e+04]"
275-
276-
fig.colorbar(im)
277-
fig.canvas.draw()# This is necessary to set up the colorbar formatter.
278-
279273
assertim.get_cursor_data(event)==10000
280274
assertim.format_cursor_data(im.get_cursor_data(event))=="[0.0+1e4]"
281275

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp