Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17420ec

Browse files
committed
Don't try to use the colorbar formatter to format RGBA data.
A colorbar doesn't make much sense for RGBA data, but matplotlib does allow one to be constructed; when formatting the cursor data for a RGBA image we must be careful to not use the colorbar formatter. Otherwise, after `plt.imshow(np.random.rand(5, 5, 3)); plt.colorbar()`, when moving the mouse cursor over the image, we get ``` <elided> File "/usr/lib/python3.7/site-packages/matplotlib/ticker.py", line 604, in format_data_short return '%-12g' % value File "/usr/lib/python3.7/site-packages/numpy/ma/core.py", line 4296, in __float__ raise TypeError("Only length-1 arrays can be converted " TypeError: Only length-1 arrays can be converted to Python scalars ```
1 parent 769dddd commit 17420ec

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ def get_cursor_data(self, event):
930930
return arr[i, j]
931931

932932
def format_cursor_data(self, data):
933-
if self.colorbar:
933+
if np.ndim(data) == 0 and self.colorbar:
934934
return (
935935
"["
936936
+ cbook.strip_math(

0 commit comments

Comments
 (0)