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

Skip to content

Commit 2883c90

Browse files
authored
Merge pull request #16741 from anntzer/rgbex
Dedupe RGBAxes examples.
2 parents 8ce9849 + 24bbc09 commit 2883c90

File tree

3 files changed

+22
-78
lines changed

3 files changed

+22
-78
lines changed

examples/axes_grid1/demo_axes_rgb.py

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@
55
66
RGBAxes to show RGB composite images.
77
"""
8+
89
import numpy as np
10+
from matplotlib import cbook
911
import matplotlib.pyplot as plt
10-
1112
from mpl_toolkits.axes_grid1.axes_rgb import make_rgb_axes, RGBAxes
1213

1314

14-
def get_demo_image():
15-
from matplotlib.cbook import get_sample_data
16-
f = get_sample_data("axes_grid/bivariate_normal.npy", asfileobj=False)
17-
z = np.load(f)
18-
# z is a numpy array of 15x15
19-
return z, (-3, 4, -4, 3)
20-
21-
2215
def get_rgb():
23-
Z, extent = get_demo_image()
16+
f = cbook.get_sample_data("axes_grid/bivariate_normal.npy")
17+
Z = np.load(f) # 15x15 numpy array.
2418

2519
Z[Z < 0] = 0.
2620
Z = Z / Z.max()
@@ -46,7 +40,14 @@ def make_cube(r, g, b):
4640
return R, G, B, RGB
4741

4842

49-
def demo_rgb():
43+
def demo_rgb1():
44+
fig = plt.figure()
45+
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)
46+
r, g, b = get_rgb()
47+
ax.imshow_rgb(r, g, b)
48+
49+
50+
def demo_rgb2():
5051
fig, ax = plt.subplots()
5152
ax_r, ax_g, ax_b = make_rgb_axes(ax, pad=0.02)
5253

@@ -57,26 +58,16 @@ def demo_rgb():
5758
ax_g.imshow(im_g)
5859
ax_b.imshow(im_b)
5960

60-
61-
def demo_rgb2():
62-
fig = plt.figure()
63-
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)
64-
65-
r, g, b = get_rgb()
66-
ax.imshow_rgb(r, g, b)
67-
68-
for ax1 in [ax.RGB, ax.R, ax.G, ax.B]:
69-
ax1.tick_params(axis='both', direction='in')
70-
for sp1 in ax1.spines.values():
61+
for ax in fig.axes:
62+
ax.tick_params(axis='both', direction='in')
63+
for sp1 in ax.spines.values():
7164
sp1.set_color("w")
72-
for tick in ax1.xaxis.get_major_ticks() + ax1.yaxis.get_major_ticks():
65+
for tick in ax.xaxis.get_major_ticks() + ax.yaxis.get_major_ticks():
7366
tick.tick1line.set_markeredgecolor("w")
7467
tick.tick2line.set_markeredgecolor("w")
7568

76-
return ax
77-
7869

79-
demo_rgb()
70+
demo_rgb1()
8071
demo_rgb2()
8172

8273
plt.show()

examples/axes_grid1/simple_rgb.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

tutorials/toolkits/axes_grid.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,16 @@
307307
from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes
308308
309309
fig = plt.figure()
310-
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8])
310+
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)
311+
r, g, b = get_rgb() # r, g, b are 2D images.
312+
ax.imshow_rgb(r, g, b)
311313
312-
r, g, b = get_rgb() # r, g, b are 2-d images
313-
ax.imshow_rgb(r, g, b,
314-
origin="lower", interpolation="nearest")
315314
316-
317-
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_rgb_001.png
318-
:target: ../../gallery/axes_grid1/simple_rgb.html
315+
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_demo_axes_rgb_001.png
316+
:target: ../../gallery/axes_grid1/demo_axes_rgb.html
319317
:align: center
320318
:scale: 50
321319
322-
Simple Rgb
323-
324320
325321
AxesDivider
326322
===========

0 commit comments

Comments
 (0)