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

Commit19b9523

Browse files
respond to code reviews, use better data source
1 parent6249be7 commit19b9523

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

‎examples/userdemo/colormap_interactive_adjustment.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33
Interactive Adjustment of Colormap Range
44
========================================
55
6-
Demonstration of using colorbarandpicker functionality to make an
6+
Demonstration of using colorbar, picker,andevent functionality to make an
77
interactively adjustable colorbar widget.
8+
9+
Left clicks and drags inside the colorbar axes adjust the high range of the
10+
color scheme. Likewise, right clicks and drags adjust the low range. The
11+
connected AxesImage immediately updates to reflect the change.
812
"""
913

1014
importnumpyasnp
1115
importmatplotlib.pyplotasplt
1216
frommatplotlib.backend_basesimportMouseButton
1317

1418

15-
defpick_fn(event):
19+
defon_pick(event):
1620
adjust_colorbar(event.mouseevent)
1721

1822

19-
defmotion_fn(mouseevent):
20-
ifmouseevent.inaxesiscolorbar.ax.axes:
23+
defon_move(mouseevent):
24+
ifmouseevent.inaxesiscolorbar.ax:
2125
adjust_colorbar(mouseevent)
2226

2327

@@ -35,18 +39,29 @@ def adjust_colorbar(mouseevent):
3539

3640
fig,ax=plt.subplots()
3741
canvas=fig.canvas
38-
arr=np.random.random((100,100))
39-
axesimage=plt.imshow(arr)
42+
43+
delta=0.1
44+
x=np.arange(-3.0,4.001,delta)
45+
y=np.arange(-4.0,3.001,delta)
46+
X,Y=np.meshgrid(x,y)
47+
Z1=np.exp(-X**2-Y**2)
48+
Z2=np.exp(-(X-1)**2- (Y-1)**2)
49+
Z= (0.9*Z1-0.5*Z2)*2
50+
51+
cmap=plt.get_cmap('viridis').with_extremes(over='xkcd:orange',under='xkcd:dark red')
52+
axesimage=plt.imshow(Z,cmap=cmap)
4053
colorbar=plt.colorbar(axesimage,ax=ax,use_gridspec=True)
4154

42-
# helps you see what value you are about to set the range to
55+
# `set_navigate` helps you see what value you are about to set the range
56+
# to, and enables zoom and pan in the colorbar which can be helpful for
57+
# narrow or wide data ranges
4358
colorbar.ax.set_navigate(True)
4459

4560
# React to all motion with left or right mouse buttons held
46-
canvas.mpl_connect("motion_notify_event",motion_fn)
61+
canvas.mpl_connect("motion_notify_event",on_move)
4762

4863
# React only to left and right clicks
49-
colorbar.ax.axes.set_picker(True)
50-
canvas.mpl_connect("pick_event",pick_fn)
64+
colorbar.ax.set_picker(True)
65+
canvas.mpl_connect("pick_event",on_pick)
5166

5267
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp