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

Appearance settings

Commit 32301f0

Browse filesBrowse files
phobson
authored andcommitted
DOC: add a basic colorbar examples
The main thing here is that we have multiple axes and use the `fig.colorbar` method, specifying which mappables should be colorbar'd next to which Axes.
1 parent 7e0cd35 commit 32301f0
Copy full SHA for 32301f0

File tree

Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-0
lines changed

‎examples/api/colorbar_basics.py

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
# setup some generic data
5+
N = 37
6+
x, y = np.mgrid[:N, :N]
7+
Z = (np.cos(x*0.2) + np.sin(y*0.3))
8+
9+
# mask out the negative and positve values, respectively
10+
Zpos = np.ma.masked_less(Z, 0)
11+
Zneg = np.ma.masked_greater(Z, 0)
12+
13+
fig, (ax1, ax2) = plt.subplots(figsize=(8, 3), ncols=2)
14+
15+
# plot just the positive data and save the
16+
# color "mappable" object returned by ax1.imshow
17+
pos = ax1.imshow(Zpos, cmap='Blues', interpolation='none')
18+
19+
# add the colorbar using the figure's method,
20+
# telling which mappable we're talking about and
21+
# which axes object it should be near
22+
fig.colorbar(pos, ax=ax1)
23+
24+
# repeat everything above for the the negative data
25+
neg = ax2.imshow(Zneg, cmap='Reds_r', interpolation='none')
26+
fig.colorbar(neg, ax=ax2)
27+
28+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.