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

Commit02a0455

Browse files
committed
Improve formatting of imshow() cursor data when a colorbar exists.
When a colorbar exists, use its formatter to format cursor data.For example, after```imshow([[10000, 10001]]); colorbar()```currently the cursor data on either pixel is rendered as 1e4, but afterthis patch it becomes 0.0+1e4 / 1.0+1e4, or 10000.0 / 10001.0 if`rcParams["axes.formatter.useoffset"]` is set to False. (Even thoughthe version with the offset text may not be the most esthetic, it'sclearly more informative than the current behavior...)It would be nice if this worked even for ScalarMappables that don'thave a colorbar; this may include extracting the Formatter selectioncode out of the colorbar code into something generally applicable toScalarMappables, or just generating a hidden colorbar "on-the-fly" ifneeded just for the purpose of getting its Formatter.
1 parentf93222a commit02a0455

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

‎lib/matplotlib/artist.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
fromcollectionsimportOrderedDict,namedtuple
22
fromfunctoolsimportwraps
33
importinspect
4+
fromnumbersimportNumber
45
importre
56
importwarnings
67

@@ -1159,8 +1160,8 @@ def format_cursor_data(self, data):
11591160
data[0]
11601161
except (TypeError,IndexError):
11611162
data= [data]
1162-
data_str=', '.join('{:0.3g}'.format(item)foritemindataif
1163-
isinstance(item,(np.floating,np.integer,int,float)))
1163+
data_str=', '.join('{:0.3g}'.format(item)foritemindata
1164+
ifisinstance(item,Number))
11641165
return"["+data_str+"]"
11651166

11661167
@property

‎lib/matplotlib/cbook/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,17 @@ def local_over_kwdict(local_var, kwargs, *keys):
302302

303303

304304
defstrip_math(s):
305-
"""remove latex formatting from mathtext"""
306-
remove= (r'\mathdefault',r'\rm',r'\cal',r'\tt',r'\it','\\','{','}')
307-
s=s[1:-1]
308-
forrinremove:
309-
s=s.replace(r,'')
305+
"""
306+
Remove latex formatting from mathtext.
307+
308+
Only handles fully math and fully non-math strings.
309+
"""
310+
ifs[:1]==s[-1:]=="$":
311+
s=s[1:-1]
312+
remove= [
313+
r'\mathdefault',r'\rm',r'\cal',r'\tt',r'\it','\\','{','}']
314+
forrinremove:
315+
s=s.replace(r,'')
310316
returns
311317

312318

‎lib/matplotlib/image.py

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

910+
defformat_cursor_data(self,data):
911+
ifself.colorbar:
912+
return (cbook.strip_math(self.colorbar.formatter(data))
913+
+cbook.strip_math(self.colorbar.formatter.get_offset()))
914+
else:
915+
returnsuper().format_cursor_data(data)
916+
910917

911918
classNonUniformImage(AxesImage):
912919
def__init__(self,ax,*,interpolation='nearest',**kwargs):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp