FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/api/image_zcoord.py at master · Nodd/matplotlib · GitHub
Nodd
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
api
/
image_zcoord.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (25 loc) · 765 Bytes
Breadcrumbs
matplotlib
/
examples
/
api
/
image_zcoord.py
Copy path
File metadata and controls
34 lines (25 loc) · 765 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
==================================
Modifying the coordinate formatter
==================================
Modify the coordinate formatter to report the image "z"
value of the nearest pixel given x and y
"""
import
numpy
as
np
import
matplotlib
.
pyplot
as
plt
# Fixing random state for reproducibility
np
.
random
.
seed
(
19680801
)
X
=
10
*
np
.
random
.
rand
(
5
,
3
)
fig
,
ax
=
plt
.
subplots
()
ax
.
imshow
(
X
,
interpolation
=
'nearest'
)
numrows
,
numcols
=
X
.
shape
def
format_coord
(
x
,
y
):
col
=
int
(
x
+
0.5
)
row
=
int
(
y
+
0.5
)
if
col
>=
0
and
col
<
numcols
and
row
>=
0
and
row
<
numrows
:
z
=
X
[
row
,
col
]
return
'x=%1.4f, y=%1.4f, z=%1.4f'
%
(
x
,
y
,
z
)
else
:
return
'x=%1.4f, y=%1.4f'
%
(
x
,
y
)
ax
.
format_coord
=
format_coord
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL