File tree 3 files changed +18
-19
lines changed
Filter options
3 files changed +18
-19
lines changed
Original file line number Diff line number Diff line change 1
1
Improved formatting of image values under cursor when a colorbar is present
2
2
```````````````````````````````````````````````````````````````````````````
3
3
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 ``.
Original file line number Diff line number Diff line change @@ -907,13 +907,17 @@ def get_cursor_data(self, event):
907
907
return arr [i , j ]
908
908
909
909
def format_cursor_data (self , data ):
910
- if self .colorbar :
911
- return ("["
912
- + cbook .strip_math (self .colorbar .formatter (data ))
913
- + cbook .strip_math (self .colorbar .formatter .get_offset ())
914
- + "]" )
915
- else :
916
- return super ().format_cursor_data (data )
910
+ if not self .colorbar :
911
+ from matplotlib .figure import Figure
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
+ + "]" )
917
921
918
922
919
923
class NonUniformImage (AxesImage ):
Original file line number Diff line number Diff line change @@ -270,12 +270,6 @@ def test_format_cursor_data():
270
270
271
271
xdisp , ydisp = ax .transData .transform_point ([0 , 0 ])
272
272
event = MouseEvent ('motion_notify_event' , fig .canvas , xdisp , ydisp )
273
- assert im .get_cursor_data (event ) == 10000
274
- assert im .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
-
279
273
assert im .get_cursor_data (event ) == 10000
280
274
assert im .format_cursor_data (im .get_cursor_data (event )) == "[0.0+1e4]"
281
275
You can’t perform that action at this time.
0 commit comments