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

Skip to content

Commit 8ae0dbf

Browse files
authored
Merge pull request #8266 from choldgraf/consolidate_annotation
Consolidate and move examples out of pylab
2 parents 459f185 + 95be2dd commit 8ae0dbf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1356
-1429
lines changed

doc/users/prev_whats_new/whats_new_0.98.4.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ psd amplitude scaling
7979

8080
Ryan May did a lot of work to rationalize the amplitude scaling of
8181
:func:`~matplotlib.pyplot.psd` and friends. See
82-
:ref:`sphx_glr_gallery_pylab_examples_psd_demo2.py`. and :ref:`sphx_glr_gallery_pylab_examples_psd_demo3.py`.
82+
:ref:`sphx_glr_gallery_pylab_examples_psd_demo.py`.
8383
The changes should increase MATLAB
8484
compatibility and increase scaling options.
8585

doc/users/prev_whats_new/whats_new_1.1.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ been improved in the presence of NANs.
119119
See the :ref:`sphx_glr_tutorials_02_intermediate_legend_guide.py` for more detailed explanation and
120120
examples.
121121

122-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_legend_demo4_001.png
123-
:target: ../../gallery/pylab_examples/legend_demo4.html
122+
.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_legend_demo_004.png
123+
:target: ../../gallery/text_labels_and_annotations/legend_demo.html
124124
:align: center
125125
:scale: 50
126126

doc/users/prev_whats_new/whats_new_1.2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ confidence intervals into the :meth:`~matplotlib.axes.boxplot` method. For
128128
every column of data passed to boxplot, the user can specify an accompanying
129129
median and confidence interval.
130130

131-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_boxplot_demo3_001.png
132-
:target: ../../gallery/pylab_examples/boxplot_demo3.html
131+
.. figure:: ../../gallery/statistics/images/sphx_glr_boxplot_demo_003.png
132+
:target: ../../gallery/statistics/boxplot_demo.html
133133
:align: center
134134
:scale: 50
135135

doc/users/prev_whats_new/whats_new_1.3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ Till Stensitzki added non-zero baselines to
154154
:func:`~matplotlib.pyplot.stackplot`. They may be symmetric or
155155
weighted.
156156

157-
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_stackplot_demo2_001.png
158-
:target: ../../gallery/pylab_examples/stackplot_demo2.html
157+
.. figure:: ../../gallery/pylab_examples/images/sphx_glr_stackplot_demo_001.png
158+
:target: ../../gallery/pylab_examples/stackplot_demo.html
159159
:align: center
160160
:scale: 50
161161

Lines changed: 163 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,176 @@
11
"""
2-
===================
3-
Displaying an image
4-
===================
2+
==========
3+
Image Demo
4+
==========
5+
6+
Many ways to plot images in Matplotlib.
7+
8+
The most common way to plot images in Matplotlib is with
9+
imshow. The following examples demonstrate much of the
10+
functionality of imshow and the many images you can create.
511
6-
Simple demo of the imshow function.
712
"""
13+
from __future__ import print_function
14+
15+
import numpy as np
16+
import matplotlib.cm as cm
17+
import matplotlib.mlab as mlab
818
import matplotlib.pyplot as plt
919
import matplotlib.cbook as cbook
20+
from matplotlib.path import Path
21+
from matplotlib.patches import PathPatch
22+
23+
###############################################################################
24+
# First we'll generate a simple bivariate normal distribution.
25+
26+
delta = 0.025
27+
x = y = np.arange(-3.0, 3.0, delta)
28+
X, Y = np.meshgrid(x, y)
29+
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
30+
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
31+
Z = Z2 - Z1 # difference of Gaussians
32+
33+
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn,
34+
origin='lower', extent=[-3, 3, -3, 3],
35+
vmax=abs(Z).max(), vmin=-abs(Z).max())
36+
37+
plt.show()
38+
39+
40+
###############################################################################
41+
# It is also possible to show images of pictures.
1042

43+
# A sample image
1144
image_file = cbook.get_sample_data('ada.png')
1245
image = plt.imread(image_file)
1346

1447
fig, ax = plt.subplots()
1548
ax.imshow(image)
1649
ax.axis('off') # clear x- and y-axes
50+
51+
52+
# And another image
53+
54+
w, h = 512, 512
55+
56+
datafile = cbook.get_sample_data('ct.raw.gz', asfileobj=True)
57+
s = datafile.read()
58+
A = np.fromstring(s, np.uint16).astype(float).reshape((w, h))
59+
A /= A.max()
60+
61+
extent = (0, 25, 0, 25)
62+
im = plt.imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent)
63+
64+
markers = [(15.9, 14.5), (16.8, 15)]
65+
x, y = zip(*markers)
66+
plt.plot(x, y, 'o')
67+
68+
plt.title('CT density')
69+
70+
plt.show()
71+
72+
73+
###############################################################################
74+
# Interpolating images
75+
# --------------------
76+
#
77+
# It is also possible to interpolate images before displaying them. Be careful,
78+
# as this may manipulate the way your data looks, but it can be helpful for
79+
# achieving the look you want. Below we'll display the same (small) array,
80+
# interpolated with three different interpolation methods.
81+
#
82+
# The center of the pixel at A[i,j] is plotted at i+0.5, i+0.5. If you
83+
# are using interpolation='nearest', the region bounded by (i,j) and
84+
# (i+1,j+1) will have the same color. If you are using interpolation,
85+
# the pixel center will have the same color as it does with nearest, but
86+
# other pixels will be interpolated between the neighboring pixels.
87+
#
88+
# Earlier versions of matplotlib (<0.63) tried to hide the edge effects
89+
# from you by setting the view limits so that they would not be visible.
90+
# A recent bugfix in antigrain, and a new implementation in the
91+
# matplotlib._image module which takes advantage of this fix, no longer
92+
# makes this necessary. To prevent edge effects, when doing
93+
# interpolation, the matplotlib._image module now pads the input array
94+
# with identical pixels around the edge. e.g., if you have a 5x5 array
95+
# with colors a-y as below::
96+
#
97+
# a b c d e
98+
# f g h i j
99+
# k l m n o
100+
# p q r s t
101+
# u v w x y
102+
#
103+
# the _image module creates the padded array,::
104+
#
105+
# a a b c d e e
106+
# a a b c d e e
107+
# f f g h i j j
108+
# k k l m n o o
109+
# p p q r s t t
110+
# o u v w x y y
111+
# o u v w x y y
112+
#
113+
# does the interpolation/resizing, and then extracts the central region.
114+
# This allows you to plot the full range of your array w/o edge effects,
115+
# and for example to layer multiple images of different sizes over one
116+
# another with different interpolation methods - see
117+
# examples/layer_images.py. It also implies a performance hit, as this
118+
# new temporary, padded array must be created. Sophisticated
119+
# interpolation also implies a performance hit, so if you need maximal
120+
# performance or have very large images, interpolation='nearest' is
121+
# suggested.
122+
123+
A = np.random.rand(5, 5)
124+
plt.figure(1)
125+
plt.imshow(A, interpolation='nearest')
126+
plt.grid(True)
127+
128+
plt.figure(2)
129+
plt.imshow(A, interpolation='bilinear')
130+
plt.grid(True)
131+
132+
plt.figure(3)
133+
plt.imshow(A, interpolation='bicubic')
134+
plt.grid(True)
135+
136+
plt.show()
137+
138+
139+
###############################################################################
140+
# You can specify whether images should be plotted with the array origin
141+
# x[0,0] in the upper left or upper right by using the origin parameter.
142+
# You can also control the default be setting image.origin in your
143+
# matplotlibrc file; see http://matplotlib.org/matplotlibrc
144+
145+
x = np.arange(120).reshape((10, 12))
146+
147+
interp = 'bilinear'
148+
fig, axs = plt.subplots(nrows=2, sharex=True, figsize=(3, 5))
149+
axs[0].set_title('blue should be up')
150+
axs[0].imshow(x, origin='upper', interpolation=interp)
151+
152+
axs[1].set_title('blue should be down')
153+
axs[1].imshow(x, origin='lower', interpolation=interp)
154+
plt.show()
155+
156+
157+
###############################################################################
158+
# Finally, we'll show an image using a clip path.
159+
160+
delta = 0.025
161+
x = y = np.arange(-3.0, 3.0, delta)
162+
X, Y = np.meshgrid(x, y)
163+
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
164+
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
165+
Z = Z2 - Z1 # difference of Gaussians
166+
167+
path = Path([[0, 1], [1, 0], [0, -1], [-1, 0], [0, 1]])
168+
patch = PathPatch(path, facecolor='none')
169+
plt.gca().add_patch(patch)
170+
171+
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
172+
origin='lower', extent=[-3, 3, -3, 3],
173+
clip_path=patch, clip_on=True)
174+
im.set_clip_path(patch)
175+
17176
plt.show()

examples/pylab_examples/annotation_demo.py

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

0 commit comments

Comments
 (0)