From 27c2dc10bb9f83026db6378c151d8108fc044af8 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 26 Mar 2018 17:02:51 -0700 Subject: [PATCH 1/4] Merge pull request #10865 from phobson/ooify-more-examples DOC: use OO-ish interface in image, contour, field examples This removes change to lib/matplotlib/axes/_base.py in PR #10865 and commit ad3a303 --- .../images_contours_and_fields/barb_demo.py | 24 +++---- .../barcode_demo.py | 8 +-- .../contour_corner_mask.py | 14 ++-- .../contour_demo.py | 68 +++++++++---------- .../contour_image.py | 58 ++++++---------- .../contour_label_demo.py | 32 +++++---- .../contourf_demo.py | 33 ++++----- .../contourf_hatching.py | 23 +++---- .../demo_bboximage.py | 12 ++-- .../figimage_demo.py | 2 +- .../images_contours_and_fields/image_demo.py | 9 +-- .../image_masked.py | 2 +- .../interpolation_methods.py | 6 +- .../quadmesh_demo.py | 3 +- .../images_contours_and_fields/quiver_demo.py | 30 ++++---- .../shading_example.py | 20 +++--- .../specgram_demo.py | 20 +++--- .../tricontour_demo.py | 26 +++---- .../tricontour_smooth_delaunay.py | 16 ++--- .../tricontour_smooth_user.py | 12 ++-- .../triinterp_demo.py | 39 ++++++----- .../tripcolor_demo.py | 34 +++++----- .../triplot_demo.py | 20 +++--- 23 files changed, 240 insertions(+), 271 deletions(-) diff --git a/examples/images_contours_and_fields/barb_demo.py b/examples/images_contours_and_fields/barb_demo.py index 12ad4d727ab2..36aa86410696 100644 --- a/examples/images_contours_and_fields/barb_demo.py +++ b/examples/images_contours_and_fields/barb_demo.py @@ -22,26 +22,23 @@ data = np.array(data, dtype=[('x', np.float32), ('y', np.float32), ('u', np.float32), ('v', np.float32)]) +fig1, axs1 = plt.subplots(nrows=2, ncols=2) # Default parameters, uniform grid -ax = plt.subplot(2, 2, 1) -ax.barbs(X, Y, U, V) +axs1[0, 0].barbs(X, Y, U, V) # Arbitrary set of vectors, make them longer and change the pivot point # (point around which they're rotated) to be the middle -ax = plt.subplot(2, 2, 2) -ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle') +axs1[0, 1].barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle') # Showing colormapping with uniform grid. Fill the circle for an empty barb, # don't round the values, and change some of the size parameters -ax = plt.subplot(2, 2, 3) -ax.barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False, - sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3)) +axs1[1, 0].barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False, + sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3)) # Change colors as well as the increments for parts of the barbs -ax = plt.subplot(2, 2, 4) -ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r', - barbcolor=['b', 'g'], - barb_increments=dict(half=10, full=20, flag=100), flip_barb=True) +axs1[1, 1].barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r', + barbcolor=['b', 'g'], flip_barb=True, + barb_increments=dict(half=10, full=20, flag=100)) # Masked arrays are also supported masked_u = np.ma.masked_array(data['u']) @@ -50,8 +47,7 @@ # Identical plot to panel 2 in the first figure, but with the point at # (0.5, 0.25) missing (masked) -fig2 = plt.figure() -ax = fig2.add_subplot(1, 1, 1) -ax.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle') +fig2, ax2 = plt.subplots() +ax2.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle') plt.show() diff --git a/examples/images_contours_and_fields/barcode_demo.py b/examples/images_contours_and_fields/barcode_demo.py index afe3700b2bb5..75227d01f42e 100644 --- a/examples/images_contours_and_fields/barcode_demo.py +++ b/examples/images_contours_and_fields/barcode_demo.py @@ -20,12 +20,12 @@ fig = plt.figure() # a vertical barcode -- this is broken at present -ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops) -ax.imshow(x.reshape((-1, 1)), **barprops) +ax1 = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops) +ax1.imshow(x.reshape((-1, 1)), **barprops) # a horizontal barcode -ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops) -ax.imshow(x.reshape((1, -1)), **barprops) +ax2 = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops) +ax2.imshow(x.reshape((1, -1)), **barprops) plt.show() diff --git a/examples/images_contours_and_fields/contour_corner_mask.py b/examples/images_contours_and_fields/contour_corner_mask.py index 1a2466bf899b..03d821959299 100644 --- a/examples/images_contours_and_fields/contour_corner_mask.py +++ b/examples/images_contours_and_fields/contour_corner_mask.py @@ -23,16 +23,16 @@ z = np.ma.array(z, mask=mask) corner_masks = [False, True] -for i, corner_mask in enumerate(corner_masks): - plt.subplot(1, 2, i + 1) - cs = plt.contourf(x, y, z, corner_mask=corner_mask) - plt.contour(cs, colors='k') - plt.title('corner_mask = {0}'.format(corner_mask)) +fig, axs = plt.subplots(ncols=2) +for ax, corner_mask in zip(axs, corner_masks): + cs = ax.contourf(x, y, z, corner_mask=corner_mask) + ax.contour(cs, colors='k') + ax.set_title('corner_mask = {0}'.format(corner_mask)) # Plot grid. - plt.grid(c='k', ls='-', alpha=0.3) + ax.grid(c='k', ls='-', alpha=0.3) # Indicate masked points with red circles. - plt.plot(np.ma.array(x, mask=~mask), y, 'ro') + ax.plot(np.ma.array(x, mask=~mask), y, 'ro') plt.show() diff --git a/examples/images_contours_and_fields/contour_demo.py b/examples/images_contours_and_fields/contour_demo.py index 4689d3507f64..a3366c88979a 100644 --- a/examples/images_contours_and_fields/contour_demo.py +++ b/examples/images_contours_and_fields/contour_demo.py @@ -30,10 +30,10 @@ # over the line segments of the contour, removing the lines beneath # the label -plt.figure() -CS = plt.contour(X, Y, Z) -plt.clabel(CS, inline=1, fontsize=10) -plt.title('Simplest default with labels') +fig, ax = plt.subplots() +CS = ax.contour(X, Y, Z) +ax.clabel(CS, inline=1, fontsize=10) +ax.set_title('Simplest default with labels') ############################################################################### @@ -41,85 +41,79 @@ # (in data coordinate). See ginput_manual_clabel.py for interactive # placement. -plt.figure() -CS = plt.contour(X, Y, Z) +fig, ax = plt.subplots() +CS = ax.contour(X, Y, Z) manual_locations = [(-1, -1.4), (-0.62, -0.7), (-2, 0.5), (1.7, 1.2), (2.0, 1.4), (2.4, 1.7)] -plt.clabel(CS, inline=1, fontsize=10, manual=manual_locations) -plt.title('labels at selected locations') +ax.clabel(CS, inline=1, fontsize=10, manual=manual_locations) +ax.set_title('labels at selected locations') ############################################################################### # You can force all the contours to be the same color. -plt.figure() -CS = plt.contour(X, Y, Z, 6, +fig, ax = plt.subplots() +CS = ax.contour(X, Y, Z, 6, colors='k', # negative contours will be dashed by default ) -plt.clabel(CS, fontsize=9, inline=1) -plt.title('Single color - negative contours dashed') +ax.clabel(CS, fontsize=9, inline=1) +ax.set_title('Single color - negative contours dashed') ############################################################################### # You can set negative contours to be solid instead of dashed: matplotlib.rcParams['contour.negative_linestyle'] = 'solid' -plt.figure() -CS = plt.contour(X, Y, Z, 6, +fig, ax = plt.subplots() +CS = ax.contour(X, Y, Z, 6, colors='k', # negative contours will be dashed by default ) -plt.clabel(CS, fontsize=9, inline=1) -plt.title('Single color - negative contours solid') +ax.clabel(CS, fontsize=9, inline=1) +ax.set_title('Single color - negative contours solid') ############################################################################### # And you can manually specify the colors of the contour -plt.figure() -CS = plt.contour(X, Y, Z, 6, +fig, ax = plt.subplots() +CS = ax.contour(X, Y, Z, 6, linewidths=np.arange(.5, 4, .5), colors=('r', 'green', 'blue', (1, 1, 0), '#afeeee', '0.5') ) -plt.clabel(CS, fontsize=9, inline=1) -plt.title('Crazy lines') +ax.clabel(CS, fontsize=9, inline=1) +ax.set_title('Crazy lines') ############################################################################### # Or you can use a colormap to specify the colors; the default # colormap will be used for the contour lines -plt.figure() -im = plt.imshow(Z, interpolation='bilinear', origin='lower', +fig, ax = plt.subplots() +im = ax.imshow(Z, interpolation='bilinear', origin='lower', cmap=cm.gray, extent=(-3, 3, -2, 2)) levels = np.arange(-1.2, 1.6, 0.2) -CS = plt.contour(Z, levels, - origin='lower', - linewidths=2, - extent=(-3, 3, -2, 2)) +CS = ax.contour(Z, levels, origin='lower', cmap='flag', + linewidths=2, extent=(-3, 3, -2, 2)) # Thicken the zero contour. zc = CS.collections[6] plt.setp(zc, linewidth=4) -plt.clabel(CS, levels[1::2], # label every second level - inline=1, - fmt='%1.1f', - fontsize=14) +ax.clabel(CS, levels[1::2], # label every second level + inline=1, fmt='%1.1f', + cmap='flag', fontsize=14) # make a colorbar for the contour lines -CB = plt.colorbar(CS, shrink=0.8, extend='both') +CB = fig.colorbar(CS, shrink=0.8, extend='both') -plt.title('Lines with colorbar') -#plt.hot() # Now change the colormap for the contour lines and colorbar -plt.flag() +ax.set_title('Lines with colorbar') # We can still add a colorbar for the image, too. -CBI = plt.colorbar(im, orientation='horizontal', shrink=0.8) +CBI = fig.colorbar(im, orientation='horizontal', shrink=0.8) # This makes the original colorbar look a bit out of place, # so let's improve its position. -l, b, w, h = plt.gca().get_position().bounds +l, b, w, h = ax.get_position().bounds ll, bb, ww, hh = CB.ax.get_position().bounds CB.ax.set_position([ll, b + 0.1*h, ww, h*0.8]) - plt.show() diff --git a/examples/images_contours_and_fields/contour_image.py b/examples/images_contours_and_fields/contour_image.py index 3f0f007dcca4..94000053e159 100644 --- a/examples/images_contours_and_fields/contour_image.py +++ b/examples/images_contours_and_fields/contour_image.py @@ -34,14 +34,12 @@ norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max()) cmap = cm.PRGn -fig = plt.figure() +fig, _axs = plt.subplots(nrows=2, ncols=2) fig.subplots_adjust(hspace=0.3) +axs = _axs.flatten() - -plt.subplot(2, 2, 1) - -cset1 = plt.contourf(X, Y, Z, levels, - cmap=cm.get_cmap(cmap, len(levels) - 1), norm=norm) +cset1 = axs[0].contourf(X, Y, Z, levels, norm=norm, + cmap=cm.get_cmap(cmap, len(levels) - 1)) # It is not necessary, but for the colormap, we need only the # number of levels minus 1. To avoid discretization error, use # either this number or a large number such as the default (256). @@ -51,7 +49,7 @@ # of the polygons in the collections returned by contourf. # Use levels output from previous call to guarantee they are the same. -cset2 = plt.contour(X, Y, Z, cset1.levels, colors='k') +cset2 = axs[0].contour(X, Y, Z, cset1.levels, colors='k') # We don't really need dashed contour lines to indicate negative # regions, so let's turn them off. @@ -64,28 +62,18 @@ # We are making a thick green line as a zero contour. # Specify the zero level as a tuple with only 0 in it. -cset3 = plt.contour(X, Y, Z, (0,), colors='g', linewidths=2) -plt.title('Filled contours') -plt.colorbar(cset1) - +cset3 = axs[0].contour(X, Y, Z, (0,), colors='g', linewidths=2) +axs[0].set_title('Filled contours') +fig.colorbar(cset1, ax=axs[0]) -plt.subplot(2, 2, 2) -plt.imshow(Z, extent=extent, cmap=cmap, norm=norm) -v = plt.axis() -plt.contour(Z, levels, colors='k', origin='upper', extent=extent) -plt.axis(v) -plt.title("Image, origin 'upper'") +axs[1].imshow(Z, extent=extent, cmap=cmap, norm=norm) +axs[1].contour(Z, levels, colors='k', origin='upper', extent=extent) +axs[1].set_title("Image, origin 'upper'") -plt.subplot(2, 2, 3) - -plt.imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm) -v = plt.axis() -plt.contour(Z, levels, colors='k', origin='lower', extent=extent) -plt.axis(v) -plt.title("Image, origin 'lower'") - -plt.subplot(2, 2, 4) +axs[2].imshow(Z, origin='lower', extent=extent, cmap=cmap, norm=norm) +axs[2].contour(Z, levels, colors='k', origin='lower', extent=extent) +axs[2].set_title("Image, origin 'lower'") # We will use the interpolation "nearest" here to show the actual # image pixels. @@ -93,15 +81,13 @@ # This is intentional. The Z values are defined at the center of each # image pixel (each color block on the following subplot), so the # domain that is contoured does not extend beyond these pixel centers. -im = plt.imshow(Z, interpolation='nearest', extent=extent, +im = axs[3].imshow(Z, interpolation='nearest', extent=extent, cmap=cmap, norm=norm) -v = plt.axis() -plt.contour(Z, levels, colors='k', origin='image', extent=extent) -plt.axis(v) -ylim = plt.get(plt.gca(), 'ylim') -plt.setp(plt.gca(), ylim=ylim[::-1]) -plt.title("Origin from rc, reversed y-axis") -plt.colorbar(im) - -plt.tight_layout() +axs[3].contour(Z, levels, colors='k', origin='image', extent=extent) +ylim = axs[3].get_ylim() +axs[3].set_ylim(ylim[::-1]) +axs[3].set_title("Origin from rc, reversed y-axis") +fig.colorbar(im, ax=axs[3]) + +fig.tight_layout() plt.show() diff --git a/examples/images_contours_and_fields/contour_label_demo.py b/examples/images_contours_and_fields/contour_label_demo.py index 7140b9b13a44..ba5e2301b20f 100644 --- a/examples/images_contours_and_fields/contour_label_demo.py +++ b/examples/images_contours_and_fields/contour_label_demo.py @@ -8,6 +8,7 @@ See also contour_demo.py. """ + import matplotlib import numpy as np import matplotlib.cm as cm @@ -32,14 +33,10 @@ # Make contour labels using creative float classes # Follows suggestion of Manuel Metz -plt.figure() - -# Basic contour plot -CS = plt.contour(X, Y, Z) - - # Define a class that forces representation of float to look a certain way # This remove trailing zero so '1.0' becomes '1' + + class nf(float): def __repr__(self): str = '%.1f' % (self.__float__(),) @@ -49,6 +46,10 @@ def __repr__(self): return '%.1f' % self.__float__() +# Basic contour plot +fig, ax = plt.subplots() +CS = ax.contour(X, Y, Z) + # Recast levels to new class CS.levels = [nf(val) for val in CS.levels] @@ -57,33 +58,34 @@ def __repr__(self): fmt = r'%r \%%' else: fmt = '%r %%' -plt.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10) + +ax.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10) ############################################################################### # Label contours with arbitrary strings using a dictionary -plt.figure() +fig1, ax1 = plt.subplots() # Basic contour plot -CS = plt.contour(X, Y, Z) +CS1 = ax1.contour(X, Y, Z) fmt = {} strs = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh'] -for l, s in zip(CS.levels, strs): +for l, s in zip(CS1.levels, strs): fmt[l] = s # Label every other level using strings -plt.clabel(CS, CS.levels[::2], inline=True, fmt=fmt, fontsize=10) +ax1.clabel(CS1, CS1.levels[::2], inline=True, fmt=fmt, fontsize=10) ############################################################################### # Use a Formatter -plt.figure() +fig2, ax2 = plt.subplots() -CS = plt.contour(X, Y, 100**Z, locator=plt.LogLocator()) +CS2 = ax2.contour(X, Y, 100**Z, locator=plt.LogLocator()) fmt = ticker.LogFormatterMathtext() fmt.create_dummy_axis() -plt.clabel(CS, CS.levels, fmt=fmt) -plt.title("$100^Z$") +ax2.clabel(CS2, CS2.levels, fmt=fmt) +ax2.set_title("$100^Z$") plt.show() diff --git a/examples/images_contours_and_fields/contourf_demo.py b/examples/images_contours_and_fields/contourf_demo.py index 41523cfdf7c2..d4becd6d8ef1 100644 --- a/examples/images_contours_and_fields/contourf_demo.py +++ b/examples/images_contours_and_fields/contourf_demo.py @@ -37,32 +37,33 @@ # this is usually not such a good idea, because they don't # occur on nice boundaries, but we do it here for purposes # of illustration. -CS = plt.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin) + +fig1, ax2 = plt.subplots() +CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin) # Note that in the following, we explicitly pass in a subset of # the contour levels used for the filled contours. Alternatively, # We could pass in additional levels to provide extra resolution, # or leave out the levels kwarg to use all of the original levels. -CS2 = plt.contour(CS, levels=CS.levels[::2], colors='r', origin=origin) +CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r', origin=origin) -plt.title('Nonsense (3 masked regions)') -plt.xlabel('word length anomaly') -plt.ylabel('sentence length anomaly') +ax2.set_title('Nonsense (3 masked regions)') +ax2.set_xlabel('word length anomaly') +ax2.set_ylabel('sentence length anomaly') # Make a colorbar for the ContourSet returned by the contourf call. -cbar = plt.colorbar(CS) +cbar = fig1.colorbar(CS) cbar.ax.set_ylabel('verbosity coefficient') # Add the contour line levels to the colorbar cbar.add_lines(CS2) -plt.figure() - +fig2, ax2 = plt.subplots() # Now make a contour plot with the levels specified, # and with the colormap generated automatically from a list # of colors. levels = [-1.5, -1, -0.5, 0, 0.5, 1] -CS3 = plt.contourf(X, Y, Z, levels, +CS3 = ax2.contourf(X, Y, Z, levels, colors=('r', 'g', 'b'), origin=origin, extend='both') @@ -72,16 +73,16 @@ CS3.cmap.set_under('yellow') CS3.cmap.set_over('cyan') -CS4 = plt.contour(X, Y, Z, levels, +CS4 = ax2.contour(X, Y, Z, levels, colors=('k',), linewidths=(3,), origin=origin) -plt.title('Listed colors (3 masked regions)') -plt.clabel(CS4, fmt='%2.1f', colors='w', fontsize=14) +ax2.set_title('Listed colors (3 masked regions)') +ax2.clabel(CS4, fmt='%2.1f', colors='w', fontsize=14) # Notice that the colorbar command gets all the information it # needs from the ContourSet object, CS3. -plt.colorbar(CS3) +fig2.colorbar(CS3) # Illustrate all 4 possible "extend" settings: extends = ["neither", "both", "min", "max"] @@ -94,12 +95,12 @@ # no effect: # cmap.set_bad("red") -fig, axs = plt.subplots(2, 2) -fig.subplots_adjust(hspace=0.3) +fig3, axs = plt.subplots(2, 2) +fig3.subplots_adjust(hspace=0.3) for ax, extend in zip(axs.ravel(), extends): cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend, origin=origin) - fig.colorbar(cs, ax=ax, shrink=0.9) + fig3.colorbar(cs, ax=ax, shrink=0.9) ax.set_title("extend = %s" % extend) ax.locator_params(nbins=4) diff --git a/examples/images_contours_and_fields/contourf_hatching.py b/examples/images_contours_and_fields/contourf_hatching.py index f13c477a9613..698f69b4ce24 100644 --- a/examples/images_contours_and_fields/contourf_hatching.py +++ b/examples/images_contours_and_fields/contourf_hatching.py @@ -20,27 +20,22 @@ ############################################################################### # Plot 1: the simplest hatched plot with a colorbar -fig = plt.figure() -cs = plt.contourf(x, y, z, hatches=['-', '/', '\\', '//'], - cmap=plt.get_cmap('gray'), - extend='both', alpha=0.5 - ) -plt.colorbar() +fig1, ax1 = plt.subplots() +cs = ax1.contourf(x, y, z, hatches=['-', '/', '\\', '//'], + cmap='gray', extend='both', alpha=0.5) +fig1.colorbar(cs) ############################################################################### # Plot 2: a plot of hatches without color with a legend -plt.figure() +fig2, ax2 = plt.subplots() n_levels = 6 -plt.contour(x, y, z, n_levels, colors='black', linestyles='-') -cs = plt.contourf(x, y, z, n_levels, colors='none', +ax2.contour(x, y, z, n_levels, colors='black', linestyles='-') +cs = ax2.contourf(x, y, z, n_levels, colors='none', hatches=['.', '/', '\\', None, '\\\\', '*'], - extend='lower' - ) + extend='lower') # create a legend for the contour set artists, labels = cs.legend_elements() -plt.legend(artists, labels, handleheight=2) - - +ax2.legend(artists, labels, handleheight=2) plt.show() diff --git a/examples/images_contours_and_fields/demo_bboximage.py b/examples/images_contours_and_fields/demo_bboximage.py index d714a6a06b43..2e774337163d 100644 --- a/examples/images_contours_and_fields/demo_bboximage.py +++ b/examples/images_contours_and_fields/demo_bboximage.py @@ -11,10 +11,9 @@ if __name__ == "__main__": - fig = plt.figure(1) - ax = plt.subplot(121) + fig, (ax1, ax2) = plt.subplots(ncols=2) - txt = ax.text(0.5, 0.5, "test", size=30, ha="center", color="w") + txt = ax1.text(0.5, 0.5, "test", size=30, ha="center", color="w") kwargs = dict() bbox_image = BboxImage(txt.get_window_extent, @@ -25,9 +24,8 @@ ) a = np.arange(256).reshape(1, 256)/256. bbox_image.set_data(a) - ax.add_artist(bbox_image) + ax1.add_artist(bbox_image) - ax = plt.subplot(122) a = np.linspace(0, 1, 256).reshape(1, -1) a = np.vstack((a, a)) @@ -51,7 +49,7 @@ bbox0 = Bbox.from_bounds(ix*dx*(1 + xpad_fraction), 1. - iy*dy*(1 + ypad_fraction) - dy, dx, dy) - bbox = TransformedBbox(bbox0, ax.transAxes) + bbox = TransformedBbox(bbox0, ax2.transAxes) bbox_image = BboxImage(bbox, cmap=plt.get_cmap(m), @@ -61,7 +59,7 @@ ) bbox_image.set_data(a) - ax.add_artist(bbox_image) + ax2.add_artist(bbox_image) plt.draw() plt.show() diff --git a/examples/images_contours_and_fields/figimage_demo.py b/examples/images_contours_and_fields/figimage_demo.py index 126c3de56e34..1c4ef70a2939 100644 --- a/examples/images_contours_and_fields/figimage_demo.py +++ b/examples/images_contours_and_fields/figimage_demo.py @@ -3,7 +3,7 @@ Figimage Demo ============= -This illustrates placing images directly in the figure, with no axes. +This illustrates placing images directly in the figure, with no Axes objects. """ import numpy as np diff --git a/examples/images_contours_and_fields/image_demo.py b/examples/images_contours_and_fields/image_demo.py index b6d8eaed9ffe..84a457a6c126 100644 --- a/examples/images_contours_and_fields/image_demo.py +++ b/examples/images_contours_and_fields/image_demo.py @@ -29,9 +29,10 @@ Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2) Z = (Z1 - Z2) * 2 -im = plt.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn, - origin='lower', extent=[-3, 3, -3, 3], - vmax=abs(Z).max(), vmin=-abs(Z).max()) +fig, ax = plt.subplots() +im = ax.imshow(Z, interpolation='bilinear', cmap=cm.RdYlGn, + origin='lower', extent=[-3, 3, -3, 3], + vmax=abs(Z).max(), vmin=-abs(Z).max()) plt.show() @@ -45,7 +46,7 @@ fig, ax = plt.subplots() ax.imshow(image) -ax.axis('off') # clear x- and y-axes +ax.axis('off') # clear x-axis and y-axis # And another image diff --git a/examples/images_contours_and_fields/image_masked.py b/examples/images_contours_and_fields/image_masked.py index 029201ef1a1b..cadba0fe9e49 100644 --- a/examples/images_contours_and_fields/image_masked.py +++ b/examples/images_contours_and_fields/image_masked.py @@ -42,7 +42,7 @@ # range to which the regular palette color scale is applied. # Anything above that range is colored based on palette.set_over, etc. -# set up the axes +# set up the Axes objets fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(6, 5.4)) # plot using 'continuous' color map diff --git a/examples/images_contours_and_fields/interpolation_methods.py b/examples/images_contours_and_fields/interpolation_methods.py index eb9ea9a19a5e..9318376f2837 100644 --- a/examples/images_contours_and_fields/interpolation_methods.py +++ b/examples/images_contours_and_fields/interpolation_methods.py @@ -27,12 +27,12 @@ grid = np.random.rand(4, 4) -fig, axes = plt.subplots(nrows=3, ncols=6, figsize=(9, 4.5), - subplot_kw={'xticks': [], 'yticks': []}) +fig, axs = plt.subplots(nrows=3, ncols=6, figsize=(9, 4.5), + subplot_kw={'xticks': [], 'yticks': []}) fig.subplots_adjust(hspace=0.3, wspace=0.05) -for ax, interp_method in zip(axes.flat, methods): +for ax, interp_method in zip(axs.flat, methods): ax.imshow(grid, interpolation=interp_method, cmap='viridis') ax.set_title(str(interp_method)) diff --git a/examples/images_contours_and_fields/quadmesh_demo.py b/examples/images_contours_and_fields/quadmesh_demo.py index 33f2b78ca4c3..0c133e34200d 100644 --- a/examples/images_contours_and_fields/quadmesh_demo.py +++ b/examples/images_contours_and_fields/quadmesh_demo.py @@ -26,7 +26,7 @@ # The color array can include masked values. Zm = np.ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z) -fig, axs = plt.subplots(1, 3) +fig, axs = plt.subplots(nrows=1, ncols=3) axs[0].pcolormesh(Qx, Qz, Z, shading='gouraud') axs[0].set_title('Without masked values') @@ -42,5 +42,4 @@ axs[2].set_title('With masked values') fig.tight_layout() - plt.show() diff --git a/examples/images_contours_and_fields/quiver_demo.py b/examples/images_contours_and_fields/quiver_demo.py index bb92e10b5bc1..636a046ee0d5 100644 --- a/examples/images_contours_and_fields/quiver_demo.py +++ b/examples/images_contours_and_fields/quiver_demo.py @@ -6,7 +6,7 @@ Known problem: the plot autoscaling does not take into account the arrows, so those on the boundaries are often out of the picture. This is *not* an easy problem to solve in a perfectly general way. -The workaround is to manually expand the axes. +The workaround is to manually expand the Axes objects. """ import matplotlib.pyplot as plt import numpy as np @@ -18,31 +18,31 @@ ############################################################################### -plt.figure() -plt.title('Arrows scale with plot width, not view') -Q = plt.quiver(X, Y, U, V, units='width') -qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E', +fig1, ax1 = plt.subplots() +ax1.set_title('Arrows scale with plot width, not view') +Q = ax1.quiver(X, Y, U, V, units='width') +qk = ax1.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E', coordinates='figure') ############################################################################### -plt.figure() -plt.title("pivot='mid'; every third arrow; units='inches'") -Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], +fig2, ax2 = plt.subplots() +ax2.set_title("pivot='mid'; every third arrow; units='inches'") +Q = ax2.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], pivot='mid', units='inches') -qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', +qk = ax2.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', coordinates='figure') -plt.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5) +ax2.scatter(X[::3, ::3], Y[::3, ::3], color='r', s=5) ############################################################################### -plt.figure() -plt.title("pivot='tip'; scales with x view") +fig3, ax3 = plt.subplots() +ax3.set_title("pivot='tip'; scales with x view") M = np.hypot(U, V) -Q = plt.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022, +Q = ax3.quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1 / 0.15) -qk = plt.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', +qk = ax3.quiverkey(Q, 0.9, 0.9, 1, r'$1 \frac{m}{s}$', labelpos='E', coordinates='figure') -plt.scatter(X, Y, color='k', s=5) +ax3.scatter(X, Y, color='k', s=5) plt.show() diff --git a/examples/images_contours_and_fields/shading_example.py b/examples/images_contours_and_fields/shading_example.py index 795d5e3a6776..ef8d171a300e 100644 --- a/examples/images_contours_and_fields/shading_example.py +++ b/examples/images_contours_and_fields/shading_example.py @@ -35,26 +35,26 @@ def main(): def compare(z, cmap, ve=1): # Create subplots and hide ticks - fig, axes = plt.subplots(ncols=2, nrows=2) - for ax in axes.flat: + fig, axs = plt.subplots(ncols=2, nrows=2) + for ax in axs.flat: ax.set(xticks=[], yticks=[]) # Illuminate the scene from the northwest ls = LightSource(azdeg=315, altdeg=45) - axes[0, 0].imshow(z, cmap=cmap) - axes[0, 0].set(xlabel='Colormapped Data') + axs[0, 0].imshow(z, cmap=cmap) + axs[0, 0].set(xlabel='Colormapped Data') - axes[0, 1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray') - axes[0, 1].set(xlabel='Illumination Intensity') + axs[0, 1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray') + axs[0, 1].set(xlabel='Illumination Intensity') rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv') - axes[1, 0].imshow(rgb) - axes[1, 0].set(xlabel='Blend Mode: "hsv" (default)') + axs[1, 0].imshow(rgb) + axs[1, 0].set(xlabel='Blend Mode: "hsv" (default)') rgb = ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='overlay') - axes[1, 1].imshow(rgb) - axes[1, 1].set(xlabel='Blend Mode: "overlay"') + axs[1, 1].imshow(rgb) + axs[1, 1].set(xlabel='Blend Mode: "overlay"') return fig diff --git a/examples/images_contours_and_fields/specgram_demo.py b/examples/images_contours_and_fields/specgram_demo.py index 15d1479826f2..681ac2ba36e6 100644 --- a/examples/images_contours_and_fields/specgram_demo.py +++ b/examples/images_contours_and_fields/specgram_demo.py @@ -11,7 +11,6 @@ # Fixing random state for reproducibility np.random.seed(19680801) - dt = 0.0005 t = np.arange(0.0, 20.0, dt) s1 = np.sin(2 * np.pi * 100 * t) @@ -25,16 +24,15 @@ nse = 0.01 * np.random.random(size=len(t)) x = s1 + s2 + nse # the signal -NFFT = 1024 # the length of the windowing segments +NFFT = 1024 # the length of the windowing segments Fs = int(1.0 / dt) # the sampling frequency -# Pxx is the segments x freqs array of instantaneous power, freqs is -# the frequency vector, bins are the centers of the time bins in which -# the power is computed, and im is the matplotlib.image.AxesImage -# instance - -ax1 = plt.subplot(211) -plt.plot(t, x) -plt.subplot(212, sharex=ax1) -Pxx, freqs, bins, im = plt.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900) +fig, (ax1, ax2) = plt.subplots(nrows=2) +ax1.plot(t, x) +Pxx, freqs, bins, im = ax2.specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900) +# The `specgram` method returns 4 objects. They are: +# - Pxx: the periodogram +# - freqs: the frequency vector +# - bins: the centers of the time bins +# - im: the matplotlib.image.AxesImage instance representing the data in the plot plt.show() diff --git a/examples/images_contours_and_fields/tricontour_demo.py b/examples/images_contours_and_fields/tricontour_demo.py index 47f8f74411ed..130ddfb02bcb 100644 --- a/examples/images_contours_and_fields/tricontour_demo.py +++ b/examples/images_contours_and_fields/tricontour_demo.py @@ -38,12 +38,12 @@ ############################################################################### # pcolor plot. -plt.figure() -plt.gca().set_aspect('equal') -plt.tricontourf(triang, z) -plt.colorbar() -plt.tricontour(triang, z, colors='k') -plt.title('Contour plot of Delaunay triangulation') +fig1, ax1 = plt.subplots() +ax1.set_aspect('equal') +tcf = ax1.tricontourf(triang, z) +fig1.colorbar(tcf) +ax1.tricontour(triang, z, colors='k') +ax1.set_title('Contour plot of Delaunay triangulation') ############################################################################### # You can specify your own triangulation rather than perform a Delaunay @@ -101,12 +101,12 @@ # object if the same triangulation was to be used more than once to save # duplicated calculations. -plt.figure() -plt.gca().set_aspect('equal') -plt.tricontourf(x, y, triangles, z) -plt.colorbar() -plt.title('Contour plot of user-specified triangulation') -plt.xlabel('Longitude (degrees)') -plt.ylabel('Latitude (degrees)') +fig2, ax2 = plt.subplots() +ax2.set_aspect('equal') +tcf = ax2.tricontourf(x, y, triangles, z) +fig2.colorbar(tcf) +ax2.set_title('Contour plot of user-specified triangulation') +ax2.set_xlabel('Longitude (degrees)') +ax2.set_ylabel('Latitude (degrees)') plt.show() diff --git a/examples/images_contours_and_fields/tricontour_smooth_delaunay.py b/examples/images_contours_and_fields/tricontour_smooth_delaunay.py index 5aa3560b9548..0af199b2fc68 100644 --- a/examples/images_contours_and_fields/tricontour_smooth_delaunay.py +++ b/examples/images_contours_and_fields/tricontour_smooth_delaunay.py @@ -114,26 +114,26 @@ def experiment_res(x, y): levels = np.arange(0., 1., 0.025) cmap = cm.get_cmap(name='Blues', lut=None) -plt.figure() -plt.gca().set_aspect('equal') -plt.title("Filtering a Delaunay mesh\n" + +fig, ax = plt.subplots() +ax.set_aspect('equal') +ax.set_title("Filtering a Delaunay mesh\n" + "(application to high-resolution tricontouring)") # 1) plot of the refined (computed) data contours: -plt.tricontour(tri_refi, z_test_refi, levels=levels, cmap=cmap, +ax.tricontour(tri_refi, z_test_refi, levels=levels, cmap=cmap, linewidths=[2.0, 0.5, 1.0, 0.5]) # 2) plot of the expected (analytical) data contours (dashed): if plot_expected: - plt.tricontour(tri_refi, z_expected, levels=levels, cmap=cmap, + ax.tricontour(tri_refi, z_expected, levels=levels, cmap=cmap, linestyles='--') # 3) plot of the fine mesh on which interpolation was done: if plot_refi_tri: - plt.triplot(tri_refi, color='0.97') + ax.triplot(tri_refi, color='0.97') # 4) plot of the initial 'coarse' mesh: if plot_tri: - plt.triplot(tri, color='0.7') + ax.triplot(tri, color='0.7') # 4) plot of the unvalidated triangles from naive Delaunay Triangulation: if plot_masked_tri: - plt.triplot(flat_tri, color='red') + ax.triplot(flat_tri, color='red') plt.show() diff --git a/examples/images_contours_and_fields/tricontour_smooth_user.py b/examples/images_contours_and_fields/tricontour_smooth_user.py index b51bcb0596cd..42b235d5543a 100644 --- a/examples/images_contours_and_fields/tricontour_smooth_user.py +++ b/examples/images_contours_and_fields/tricontour_smooth_user.py @@ -62,17 +62,17 @@ def function_z(x, y): #----------------------------------------------------------------------------- # Plot the triangulation and the high-res iso-contours #----------------------------------------------------------------------------- -plt.figure() -plt.gca().set_aspect('equal') -plt.triplot(triang, lw=0.5, color='white') +fig, ax = plt.subplots() +ax.set_aspect('equal') +ax.triplot(triang, lw=0.5, color='white') levels = np.arange(0., 1., 0.025) cmap = cm.get_cmap(name='terrain', lut=None) -plt.tricontourf(tri_refi, z_test_refi, levels=levels, cmap=cmap) -plt.tricontour(tri_refi, z_test_refi, levels=levels, +ax.tricontourf(tri_refi, z_test_refi, levels=levels, cmap=cmap) +ax.tricontour(tri_refi, z_test_refi, levels=levels, colors=['0.25', '0.5', '0.5', '0.5', '0.5'], linewidths=[1.0, 0.5, 0.5, 0.5, 0.5]) -plt.title("High-resolution tricontouring") +ax.set_title("High-resolution tricontouring") plt.show() diff --git a/examples/images_contours_and_fields/triinterp_demo.py b/examples/images_contours_and_fields/triinterp_demo.py index 9f8dacf0520f..650a4b621fe1 100644 --- a/examples/images_contours_and_fields/triinterp_demo.py +++ b/examples/images_contours_and_fields/triinterp_demo.py @@ -29,33 +29,32 @@ interp_cubic_min_E = mtri.CubicTriInterpolator(triang, z, kind='min_E') zi_cubic_min_E = interp_cubic_min_E(xi, yi) +# Set up the figure +fig, axs = plt.subplots(nrows=2, ncols=2) +axs = axs.flatten() # Plot the triangulation. -plt.subplot(221) -plt.tricontourf(triang, z) -plt.triplot(triang, 'ko-') -plt.title('Triangular grid') +axs[0].tricontourf(triang, z) +axs[0].triplot(triang, 'ko-') +axs[0].set_title('Triangular grid') # Plot linear interpolation to quad grid. -plt.subplot(222) -plt.contourf(xi, yi, zi_lin) -plt.plot(xi, yi, 'k-', lw=0.5, alpha=0.5) -plt.plot(xi.T, yi.T, 'k-', lw=0.5, alpha=0.5) -plt.title("Linear interpolation") +axs[1].contourf(xi, yi, zi_lin) +axs[1].plot(xi, yi, 'k-', lw=0.5, alpha=0.5) +axs[1].plot(xi.T, yi.T, 'k-', lw=0.5, alpha=0.5) +axs[1].set_title("Linear interpolation") # Plot cubic interpolation to quad grid, kind=geom -plt.subplot(223) -plt.contourf(xi, yi, zi_cubic_geom) -plt.plot(xi, yi, 'k-', lw=0.5, alpha=0.5) -plt.plot(xi.T, yi.T, 'k-', lw=0.5, alpha=0.5) -plt.title("Cubic interpolation,\nkind='geom'") +axs[2].contourf(xi, yi, zi_cubic_geom) +axs[2].plot(xi, yi, 'k-', lw=0.5, alpha=0.5) +axs[2].plot(xi.T, yi.T, 'k-', lw=0.5, alpha=0.5) +axs[2].set_title("Cubic interpolation,\nkind='geom'") # Plot cubic interpolation to quad grid, kind=min_E -plt.subplot(224) -plt.contourf(xi, yi, zi_cubic_min_E) -plt.plot(xi, yi, 'k-', lw=0.5, alpha=0.5) -plt.plot(xi.T, yi.T, 'k-', lw=0.5, alpha=0.5) -plt.title("Cubic interpolation,\nkind='min_E'") +axs[3].contourf(xi, yi, zi_cubic_min_E) +axs[3].plot(xi, yi, 'k-', lw=0.5, alpha=0.5) +axs[3].plot(xi.T, yi.T, 'k-', lw=0.5, alpha=0.5) +axs[3].set_title("Cubic interpolation,\nkind='min_E'") -plt.tight_layout() +fig.tight_layout() plt.show() diff --git a/examples/images_contours_and_fields/tripcolor_demo.py b/examples/images_contours_and_fields/tripcolor_demo.py index 8c885744895d..877d434ae1e1 100644 --- a/examples/images_contours_and_fields/tripcolor_demo.py +++ b/examples/images_contours_and_fields/tripcolor_demo.py @@ -38,20 +38,20 @@ ############################################################################### # tripcolor plot. -plt.figure() -plt.gca().set_aspect('equal') -plt.tripcolor(triang, z, shading='flat') -plt.colorbar() -plt.title('tripcolor of Delaunay triangulation, flat shading') +fig1, ax1 = plt.subplots() +ax1.set_aspect('equal') +tpc = ax1.tripcolor(triang, z, shading='flat') +fig1.colorbar(tpc) +ax1.set_title('tripcolor of Delaunay triangulation, flat shading') ############################################################################### # Illustrate Gouraud shading. -plt.figure() -plt.gca().set_aspect('equal') -plt.tripcolor(triang, z, shading='gouraud') -plt.colorbar() -plt.title('tripcolor of Delaunay triangulation, gouraud shading') +fig2, ax2 = plt.subplots() +ax2.set_aspect('equal') +tpc = ax2.tripcolor(triang, z, shading='gouraud') +fig2.colorbar(tpc) +ax2.set_title('tripcolor of Delaunay triangulation, gouraud shading') ############################################################################### @@ -115,12 +115,12 @@ # Can specify one color value per face rather than one per point by using the # facecolors kwarg. -plt.figure() -plt.gca().set_aspect('equal') -plt.tripcolor(x, y, triangles, facecolors=zfaces, edgecolors='k') -plt.colorbar() -plt.title('tripcolor of user-specified triangulation') -plt.xlabel('Longitude (degrees)') -plt.ylabel('Latitude (degrees)') +fig3, ax3 = plt.subplots() +ax3.set_aspect('equal') +tpc = ax3.tripcolor(x, y, triangles, facecolors=zfaces, edgecolors='k') +fig3.colorbar(tpc) +ax3.set_title('tripcolor of user-specified triangulation') +ax3.set_xlabel('Longitude (degrees)') +ax3.set_ylabel('Latitude (degrees)') plt.show() diff --git a/examples/images_contours_and_fields/triplot_demo.py b/examples/images_contours_and_fields/triplot_demo.py index d3a65762d021..0efc7011b4a8 100644 --- a/examples/images_contours_and_fields/triplot_demo.py +++ b/examples/images_contours_and_fields/triplot_demo.py @@ -37,10 +37,10 @@ ############################################################################### # Plot the triangulation. -plt.figure() -plt.gca().set_aspect('equal') -plt.triplot(triang, 'bo-', lw=1) -plt.title('triplot of Delaunay triangulation') +fig1, ax1 = plt.subplots() +ax1.set_aspect('equal') +ax1.triplot(triang, 'bo-', lw=1) +ax1.set_title('triplot of Delaunay triangulation') ############################################################################### @@ -96,11 +96,11 @@ # if the same triangulation was to be used more than once to save duplicated # calculations. -plt.figure() -plt.gca().set_aspect('equal') -plt.triplot(x, y, triangles, 'go-', lw=1.0) -plt.title('triplot of user-specified triangulation') -plt.xlabel('Longitude (degrees)') -plt.ylabel('Latitude (degrees)') +fig2, ax2 = plt.subplots() +ax2.set_aspect('equal') +ax2.triplot(x, y, triangles, 'go-', lw=1.0) +ax2.set_title('triplot of user-specified triangulation') +ax2.set_xlabel('Longitude (degrees)') +ax2.set_ylabel('Latitude (degrees)') plt.show() From b5a6525ef07bf0d8aad28b2fa68b94dbc098a1e8 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 9 May 2018 10:15:46 -0700 Subject: [PATCH 2/4] Merge pull request #11191 from ImportanceOfBeingErnest/example-refs_imgscntrs DOC: Adding example references for Images,contours,fields section --- .../affine_image.py | 23 ++++ .../images_contours_and_fields/barb_demo.py | 15 +++ .../barcode_demo.py | 17 ++- .../contour_corner_mask.py | 20 +++- .../contour_demo.py | 26 ++++- .../contour_image.py | 28 ++++- .../contour_label_demo.py | 23 +++- .../contourf_demo.py | 26 ++++- .../contourf_hatching.py | 22 ++++ .../contourf_log.py | 19 ++++ .../images_contours_and_fields/custom_cmap.py | 31 ++++- .../demo_bboximage.py | 106 +++++++++++------- .../figimage_demo.py | 14 +++ .../image_clip_path.py | 15 +++ .../images_contours_and_fields/image_demo.py | 25 ++++- .../image_masked.py | 19 ++++ .../image_transparency_blend.py | 18 +++ .../interpolation_methods.py | 35 ++++-- .../layer_images.py | 14 +++ .../images_contours_and_fields/matshow.py | 16 ++- .../images_contours_and_fields/multi_image.py | 21 ++++ .../images_contours_and_fields/pcolor_demo.py | 31 ++++- .../pcolormesh_levels.py | 8 +- .../plot_streamplot.py | 17 ++- .../quadmesh_demo.py | 19 +++- .../images_contours_and_fields/quiver_demo.py | 19 ++++ .../quiver_simple_demo.py | 22 +++- .../shading_example.py | 14 +++ .../specgram_demo.py | 17 ++- .../images_contours_and_fields/spy_demos.py | 16 ++- .../tricontour_demo.py | 15 +++ .../tricontour_smooth_delaunay.py | 30 ++++- .../tricontour_smooth_user.py | 21 +++- .../trigradient_demo.py | 26 ++++- .../triinterp_demo.py | 24 ++++ .../tripcolor_demo.py | 16 +++ .../triplot_demo.py | 16 +++ tutorials/advanced/transforms_tutorial.py | 6 +- 38 files changed, 757 insertions(+), 93 deletions(-) diff --git a/examples/images_contours_and_fields/affine_image.py b/examples/images_contours_and_fields/affine_image.py index 67606d932daa..fadefa089e0f 100644 --- a/examples/images_contours_and_fields/affine_image.py +++ b/examples/images_contours_and_fields/affine_image.py @@ -3,6 +3,13 @@ Affine transform of an image ============================ + +Prepending an affine transformation (:class:`~.transforms.Affine2D`) +to the :ref:`data transform ` +of an image allows to manipulate the image's shape and orientation. +This is an example of the concept of +:ref:`transform chaining `. + For the backends that support draw_image with optional affine transform (e.g., agg, ps backend), the image of the output should have its boundary match the dashed yellow rectangle. @@ -57,3 +64,19 @@ def do_plot(ax, Z, transform): rotate_deg(30).skew_deg(30, 15).scale(-1, .5).translate(.5, -1)) plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.transforms.Affine2D diff --git a/examples/images_contours_and_fields/barb_demo.py b/examples/images_contours_and_fields/barb_demo.py index 36aa86410696..00331d64a703 100644 --- a/examples/images_contours_and_fields/barb_demo.py +++ b/examples/images_contours_and_fields/barb_demo.py @@ -51,3 +51,18 @@ ax2.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.barbs +matplotlib.pyplot.barbs + diff --git a/examples/images_contours_and_fields/barcode_demo.py b/examples/images_contours_and_fields/barcode_demo.py index 75227d01f42e..866154523c0f 100644 --- a/examples/images_contours_and_fields/barcode_demo.py +++ b/examples/images_contours_and_fields/barcode_demo.py @@ -3,6 +3,7 @@ Barcode Demo ============ +This demo shows how to produce a one-dimensional image, or "bar code". """ import matplotlib.pyplot as plt import numpy as np @@ -19,7 +20,7 @@ fig = plt.figure() -# a vertical barcode -- this is broken at present +# a vertical barcode ax1 = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops) ax1.imshow(x.reshape((-1, 1)), **barprops) @@ -29,3 +30,17 @@ plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow diff --git a/examples/images_contours_and_fields/contour_corner_mask.py b/examples/images_contours_and_fields/contour_corner_mask.py index 03d821959299..0482945d552b 100644 --- a/examples/images_contours_and_fields/contour_corner_mask.py +++ b/examples/images_contours_and_fields/contour_corner_mask.py @@ -3,8 +3,8 @@ Contour Corner Mask =================== -Illustrate the difference between corner_mask=False and corner_mask=True -for masked contour plots. +Illustrate the difference between ``corner_mask=False`` and +``corner_mask=True`` for masked contour plots. """ import matplotlib.pyplot as plt import numpy as np @@ -36,3 +36,19 @@ ax.plot(np.ma.array(x, mask=~mask), y, 'ro') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.contour +matplotlib.pyplot.contour +matplotlib.axes.Axes.contourf +matplotlib.pyplot.contourf diff --git a/examples/images_contours_and_fields/contour_demo.py b/examples/images_contours_and_fields/contour_demo.py index a3366c88979a..5fe006134051 100644 --- a/examples/images_contours_and_fields/contour_demo.py +++ b/examples/images_contours_and_fields/contour_demo.py @@ -6,15 +6,15 @@ Illustrate simple contour plotting, contours on an image with a colorbar for the contours, and labelled contours. -See also contour_image.py. +See also the +:ref:`contour image example +`. """ import matplotlib import numpy as np import matplotlib.cm as cm import matplotlib.pyplot as plt -matplotlib.rcParams['xtick.direction'] = 'out' -matplotlib.rcParams['ytick.direction'] = 'out' delta = 0.025 x = np.arange(-3.0, 3.0, delta) @@ -117,3 +117,23 @@ CB.ax.set_position([ll, b + 0.1*h, ww, h*0.8]) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.contour +matplotlib.pyplot.contour +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.axes.Axes.clabel +matplotlib.pyplot.clabel +matplotlib.axes.Axes.set_position +matplotlib.axes.Axes.get_position diff --git a/examples/images_contours_and_fields/contour_image.py b/examples/images_contours_and_fields/contour_image.py index 94000053e159..9bfe4d9fe546 100644 --- a/examples/images_contours_and_fields/contour_image.py +++ b/examples/images_contours_and_fields/contour_image.py @@ -4,11 +4,15 @@ ============= Test combinations of contouring, filled contouring, and image plotting. -For contour labelling, see contour_demo.py. +For contour labelling, see See also the +:ref:`contour demo example +`. The emphasis in this demo is on showing how to make contours register correctly on images, and on how to get both of them oriented as -desired. In particular, note the usage of the "origin" and "extent" +desired. In particular, note the usage of the +:ref:`"origin" and "extent" +` keyword arguments to imshow and contour. """ import matplotlib.pyplot as plt @@ -91,3 +95,23 @@ fig.tight_layout() plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.contour +matplotlib.pyplot.contour +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.colors.Normalize diff --git a/examples/images_contours_and_fields/contour_label_demo.py b/examples/images_contours_and_fields/contour_label_demo.py index ba5e2301b20f..b3c2c75cb801 100644 --- a/examples/images_contours_and_fields/contour_label_demo.py +++ b/examples/images_contours_and_fields/contour_label_demo.py @@ -6,7 +6,8 @@ Illustrate some of the more advanced things that one can do with contour labels. -See also contour_demo.py. +See also the :ref:`contour demo example +`. """ import matplotlib @@ -15,9 +16,6 @@ import matplotlib.ticker as ticker import matplotlib.pyplot as plt -matplotlib.rcParams['xtick.direction'] = 'out' -matplotlib.rcParams['ytick.direction'] = 'out' - ############################################################################### # Define our surface @@ -89,3 +87,20 @@ def __repr__(self): ax2.set_title("$100^Z$") plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +matplotlib.axes.Axes.contour +matplotlib.pyplot.contour +matplotlib.axes.Axes.clabel +matplotlib.pyplot.clabel +matplotlib.ticker.LogFormatterMathtext +matplotlib.ticker.TickHelper.create_dummy_axis diff --git a/examples/images_contours_and_fields/contourf_demo.py b/examples/images_contours_and_fields/contourf_demo.py index d4becd6d8ef1..04e3dd6bdd0e 100644 --- a/examples/images_contours_and_fields/contourf_demo.py +++ b/examples/images_contours_and_fields/contourf_demo.py @@ -3,7 +3,7 @@ Contourf Demo ============= -How to use the ``contourf`` function to create filled contour plots. +How to use the :meth:`.axes.Axes.contourf` method to create filled contour plots. """ import numpy as np import matplotlib.pyplot as plt @@ -105,3 +105,27 @@ ax.locator_params(nbins=4) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.contour +matplotlib.pyplot.contour +matplotlib.axes.Axes.contourf +matplotlib.pyplot.contourf +matplotlib.axes.Axes.clabel +matplotlib.pyplot.clabel +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.colors.Colormap +matplotlib.colors.Colormap.set_bad +matplotlib.colors.Colormap.set_under +matplotlib.colors.Colormap.set_over diff --git a/examples/images_contours_and_fields/contourf_hatching.py b/examples/images_contours_and_fields/contourf_hatching.py index 698f69b4ce24..ca76e7338f2d 100644 --- a/examples/images_contours_and_fields/contourf_hatching.py +++ b/examples/images_contours_and_fields/contourf_hatching.py @@ -39,3 +39,25 @@ artists, labels = cs.legend_elements() ax2.legend(artists, labels, handleheight=2) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.contour +matplotlib.pyplot.contour +matplotlib.axes.Axes.contourf +matplotlib.pyplot.contourf +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.axes.Axes.legend +matplotlib.pyplot.legend +matplotlib.contour.ContourSet +matplotlib.contour.ContourSet.legend_elements diff --git a/examples/images_contours_and_fields/contourf_log.py b/examples/images_contours_and_fields/contourf_log.py index 96ee55c51215..d7696e516676 100644 --- a/examples/images_contours_and_fields/contourf_log.py +++ b/examples/images_contours_and_fields/contourf_log.py @@ -49,3 +49,22 @@ cbar = fig.colorbar(cs) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.contourf +matplotlib.pyplot.contourf +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.axes.Axes.legend +matplotlib.pyplot.legend +matplotlib.ticker.LogLocator diff --git a/examples/images_contours_and_fields/custom_cmap.py b/examples/images_contours_and_fields/custom_cmap.py index 0430eaa354b1..5334576ec044 100644 --- a/examples/images_contours_and_fields/custom_cmap.py +++ b/examples/images_contours_and_fields/custom_cmap.py @@ -3,9 +3,11 @@ Creating a colormap from a list of colors ========================================= -Creating a colormap from a list of colors can be done with the `from_list` -method of `LinearSegmentedColormap`. You must pass a list of RGB tuples that -define the mixture of colors from 0 to 1. +Creating a :ref:`colormap ` +from a list of colors can be done with the +:meth:`~.colors.LinearSegmentedColormap.from_list` method of +`LinearSegmentedColormap`. You must pass a list of RGB tuples that define the +mixture of colors from 0 to 1. Creating custom colormaps @@ -222,3 +224,26 @@ fig.subplots_adjust(top=0.9) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.colors +matplotlib.colors.LinearSegmentedColormap +matplotlib.colors.LinearSegmentedColormap.from_list +matplotlib.cm +matplotlib.cm.ScalarMappable.set_cmap +matplotlib.pyplot.register_cmap +matplotlib.cm.register_cmap diff --git a/examples/images_contours_and_fields/demo_bboximage.py b/examples/images_contours_and_fields/demo_bboximage.py index 2e774337163d..7ea364af4f5d 100644 --- a/examples/images_contours_and_fields/demo_bboximage.py +++ b/examples/images_contours_and_fields/demo_bboximage.py @@ -1,65 +1,87 @@ """ ============== -Demo BboxImage +BboxImage Demo ============== +A :class:`~matplotlib.image.BboxImage` can be used to position +an image according to a bounding box. This demo shows how to +show an image inside a `text.Text`'s bounding box as well as +how to manually create a bounding box for the image. """ import matplotlib.pyplot as plt import numpy as np from matplotlib.image import BboxImage from matplotlib.transforms import Bbox, TransformedBbox -if __name__ == "__main__": - fig, (ax1, ax2) = plt.subplots(ncols=2) +fig, (ax1, ax2) = plt.subplots(ncols=2) - txt = ax1.text(0.5, 0.5, "test", size=30, ha="center", color="w") - kwargs = dict() +# ---------------------------- +# Create a BboxImage with Text +# ---------------------------- +txt = ax1.text(0.5, 0.5, "test", size=30, ha="center", color="w") +kwargs = dict() - bbox_image = BboxImage(txt.get_window_extent, - norm=None, - origin=None, - clip_on=False, - **kwargs - ) - a = np.arange(256).reshape(1, 256)/256. - bbox_image.set_data(a) - ax1.add_artist(bbox_image) +bbox_image = BboxImage(txt.get_window_extent, + norm=None, + origin=None, + clip_on=False, + **kwargs + ) +a = np.arange(256).reshape(1, 256)/256. +bbox_image.set_data(a) +ax1.add_artist(bbox_image) + +# ------------------------------------ +# Create a BboxImage for each colormap +# ------------------------------------ +a = np.linspace(0, 1, 256).reshape(1, -1) +a = np.vstack((a, a)) - a = np.linspace(0, 1, 256).reshape(1, -1) - a = np.vstack((a, a)) +# List of all colormaps; skip reversed colormaps. +maps = sorted(m for m in plt.cm.cmap_d if not m.endswith("_r")) - maps = sorted(m for m in plt.cm.cmap_d - if not m.endswith("_r")) # Skip reversed colormaps. +ncol = 2 +nrow = len(maps)//ncol + 1 - # fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99) +xpad_fraction = 0.3 +dx = 1./(ncol + xpad_fraction*(ncol - 1)) - ncol = 2 - nrow = len(maps)//ncol + 1 +ypad_fraction = 0.3 +dy = 1./(nrow + ypad_fraction*(nrow - 1)) - xpad_fraction = 0.3 - dx = 1./(ncol + xpad_fraction*(ncol - 1)) +for i, m in enumerate(maps): + ix, iy = divmod(i, nrow) - ypad_fraction = 0.3 - dy = 1./(nrow + ypad_fraction*(nrow - 1)) + bbox0 = Bbox.from_bounds(ix*dx*(1 + xpad_fraction), + 1. - iy*dy*(1 + ypad_fraction) - dy, + dx, dy) + bbox = TransformedBbox(bbox0, ax2.transAxes) - for i, m in enumerate(maps): - ix, iy = divmod(i, nrow) - # plt.figimage(a, 10, i*10, cmap=plt.get_cmap(m), origin='lower') - bbox0 = Bbox.from_bounds(ix*dx*(1 + xpad_fraction), - 1. - iy*dy*(1 + ypad_fraction) - dy, - dx, dy) - bbox = TransformedBbox(bbox0, ax2.transAxes) + bbox_image = BboxImage(bbox, + cmap=plt.get_cmap(m), + norm=None, + origin=None, + **kwargs + ) + + bbox_image.set_data(a) + ax2.add_artist(bbox_image) - bbox_image = BboxImage(bbox, - cmap=plt.get_cmap(m), - norm=None, - origin=None, - **kwargs - ) +plt.show() - bbox_image.set_data(a) - ax2.add_artist(bbox_image) +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: - plt.draw() - plt.show() +import matplotlib +matplotlib.image.BboxImage +matplotlib.transforms.Bbox +matplotlib.transforms.TransformedBbox +matplotlib.text.Text diff --git a/examples/images_contours_and_fields/figimage_demo.py b/examples/images_contours_and_fields/figimage_demo.py index 1c4ef70a2939..b2ce013d77a5 100644 --- a/examples/images_contours_and_fields/figimage_demo.py +++ b/examples/images_contours_and_fields/figimage_demo.py @@ -20,3 +20,17 @@ im2 = fig.figimage(Z, xo=100, yo=100, alpha=.8, origin='lower') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +matplotlib.figure.Figure +matplotlib.figure.Figure.figimage +matplotlib.pyplot.figimage diff --git a/examples/images_contours_and_fields/image_clip_path.py b/examples/images_contours_and_fields/image_clip_path.py index e444ee1195bf..e8c3d4fe1abd 100644 --- a/examples/images_contours_and_fields/image_clip_path.py +++ b/examples/images_contours_and_fields/image_clip_path.py @@ -20,3 +20,18 @@ ax.axis('off') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.artist.Artist.set_clip_path diff --git a/examples/images_contours_and_fields/image_demo.py b/examples/images_contours_and_fields/image_demo.py index 84a457a6c126..4e8e14033b6e 100644 --- a/examples/images_contours_and_fields/image_demo.py +++ b/examples/images_contours_and_fields/image_demo.py @@ -6,7 +6,7 @@ Many ways to plot images in Matplotlib. The most common way to plot images in Matplotlib is with -imshow. The following examples demonstrate much of the +:meth:`~.axes.Axes.imshow`. The following examples demonstrate much of the functionality of imshow and the many images you can create. """ @@ -115,7 +115,8 @@ # This allows you to plot the full range of your array w/o edge effects, # and for example to layer multiple images of different sizes over one # another with different interpolation methods - see -# examples/layer_images.py. It also implies a performance hit, as this +# :ref:`sphx_glr_gallery_images_contours_and_fields_layer_images.py`. +# It also implies a performance hit, as this # new temporary, padded array must be created. Sophisticated # interpolation also implies a performance hit, so if you need maximal # performance or have very large images, interpolation='nearest' is @@ -136,7 +137,9 @@ # You can specify whether images should be plotted with the array origin # x[0,0] in the upper left or lower right by using the origin parameter. # You can also control the default setting image.origin in your -# :ref:`matplotlibrc file ` +# :ref:`matplotlibrc file `. For more on +# this topic see the :ref:`complete guide on origin and extent +# `. x = np.arange(120).reshape((10, 12)) @@ -172,3 +175,19 @@ im.set_clip_path(patch) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.artist.Artist.set_clip_path +matplotlib.patches.PathPatch diff --git a/examples/images_contours_and_fields/image_masked.py b/examples/images_contours_and_fields/image_masked.py index cadba0fe9e49..af718c8536b7 100644 --- a/examples/images_contours_and_fields/image_masked.py +++ b/examples/images_contours_and_fields/image_masked.py @@ -73,3 +73,22 @@ fig.suptitle('imshow, with out-of-range and masked data') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.colors.BoundaryNorm +matplotlib.colorbar.ColorbarBase.set_label + diff --git a/examples/images_contours_and_fields/image_transparency_blend.py b/examples/images_contours_and_fields/image_transparency_blend.py index 0f9ce59506aa..ad2f76ef3c95 100644 --- a/examples/images_contours_and_fields/image_transparency_blend.py +++ b/examples/images_contours_and_fields/image_transparency_blend.py @@ -124,3 +124,21 @@ def normal_pdf(x, mean, var): ax.contour(weights[::-1], levels=[-.0001, .0001], colors='k', linestyles='-') ax.set_axis_off() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.axes.Axes.contour +matplotlib.pyplot.contour +matplotlib.colors.Normalize +matplotlib.axes.Axes.set_axis_off diff --git a/examples/images_contours_and_fields/interpolation_methods.py b/examples/images_contours_and_fields/interpolation_methods.py index 9318376f2837..3e90986237b6 100644 --- a/examples/images_contours_and_fields/interpolation_methods.py +++ b/examples/images_contours_and_fields/interpolation_methods.py @@ -3,16 +3,17 @@ Interpolations for imshow/matshow ================================= -This example displays the difference between interpolation methods for imshow -and matshow. +This example displays the difference between interpolation methods for +:meth:`~.axes.Axes.imshow` and :meth:`~.axes.Axes.matshow`. -If `interpolation` is None, it defaults to the rc image.interpolation -parameter. If the interpolation is `none`, then no interpolation is performed -for the Agg, ps and pdf backends. Other backends will default to 'nearest'. +If `interpolation` is None, it defaults to the ``image.interpolation`` +:ref:`rc parameter `. +If the interpolation is ``'none'``, then no interpolation is performed +for the Agg, ps and pdf backends. Other backends will default to ``'nearest'``. -For the Agg, ps and pdf backends, interpolation = 'none' works well when a big -image is scaled down, while interpolation = 'nearest' works well when a small -image is scaled up. +For the Agg, ps and pdf backends, ``interpolation = 'none'`` works well when a +big image is scaled down, while ``interpolation = 'nearest'`` works well when +a small image is scaled up. """ import matplotlib.pyplot as plt @@ -27,10 +28,10 @@ grid = np.random.rand(4, 4) -fig, axs = plt.subplots(nrows=3, ncols=6, figsize=(9, 4.5), +fig, axs = plt.subplots(nrows=3, ncols=6, figsize=(9.3, 6), subplot_kw={'xticks': [], 'yticks': []}) -fig.subplots_adjust(hspace=0.3, wspace=0.05) +fig.subplots_adjust(left=0.03, right=0.97, hspace=0.3, wspace=0.05) for ax, interp_method in zip(axs.flat, methods): ax.imshow(grid, interpolation=interp_method, cmap='viridis') @@ -38,3 +39,17 @@ plt.tight_layout() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow diff --git a/examples/images_contours_and_fields/layer_images.py b/examples/images_contours_and_fields/layer_images.py index 725876045924..ada6757490bc 100644 --- a/examples/images_contours_and_fields/layer_images.py +++ b/examples/images_contours_and_fields/layer_images.py @@ -41,3 +41,17 @@ def func3(x, y): extent=extent) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow diff --git a/examples/images_contours_and_fields/matshow.py b/examples/images_contours_and_fields/matshow.py index ce940670a7c2..4980e116a110 100644 --- a/examples/images_contours_and_fields/matshow.py +++ b/examples/images_contours_and_fields/matshow.py @@ -3,7 +3,7 @@ Matshow ======= -Simple matshow() example. +Simple `~.axes.Axes.matshow` example. """ import matplotlib.pyplot as plt import numpy as np @@ -21,3 +21,17 @@ def samplemat(dims): plt.matshow(samplemat((15, 15))) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.matshow +matplotlib.pyplot.matshow diff --git a/examples/images_contours_and_fields/multi_image.py b/examples/images_contours_and_fields/multi_image.py index 6f6b3565b3bf..e8df23d1d81e 100644 --- a/examples/images_contours_and_fields/multi_image.py +++ b/examples/images_contours_and_fields/multi_image.py @@ -51,3 +51,24 @@ def update(changed_image): im.callbacksSM.connect('changed', update) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.colors.Normalize +matplotlib.cm.ScalarMappable.set_cmap +matplotlib.cm.ScalarMappable.set_norm +matplotlib.cm.ScalarMappable.set_clim +matplotlib.cbook.CallbackRegistry.connect diff --git a/examples/images_contours_and_fields/pcolor_demo.py b/examples/images_contours_and_fields/pcolor_demo.py index 37927f241318..551b3238d145 100644 --- a/examples/images_contours_and_fields/pcolor_demo.py +++ b/examples/images_contours_and_fields/pcolor_demo.py @@ -3,10 +3,10 @@ Pcolor Demo =========== -Generating images with pcolor. +Generating images with :meth:`~.axes.Axes.pcolor`. Pcolor allows you to generate 2-D image-style plots. Below we will show how -to do so in Matplotlib. +to do so in Matplotlib. """ import matplotlib.pyplot as plt import numpy as np @@ -33,8 +33,9 @@ # Comparing pcolor with similar functions # --------------------------------------- # -# Demonstrates similarities between pcolor, pcolormesh, imshow and pcolorfast -# for drawing quadrilateral grids. +# Demonstrates similarities between :meth:`~.axes.Axes.pcolor`, +# :meth:`~.axes.Axes.pcolormesh`, :meth:`~.axes.Axes.imshow` and +# :meth:`~.axes.Axes.pcolorfast` for drawing quadrilateral grids. # make these smaller to increase the resolution dx, dy = 0.15, 0.05 @@ -106,3 +107,25 @@ fig.colorbar(c, ax=ax1) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.pcolor +matplotlib.pyplot.pcolor +matplotlib.axes.Axes.pcolormesh +matplotlib.pyplot.pcolormesh +matplotlib.axes.Axes.pcolorfast +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.colors.LogNorm diff --git a/examples/images_contours_and_fields/pcolormesh_levels.py b/examples/images_contours_and_fields/pcolormesh_levels.py index 1a75b129aa28..f5554a3d4641 100644 --- a/examples/images_contours_and_fields/pcolormesh_levels.py +++ b/examples/images_contours_and_fields/pcolormesh_levels.py @@ -4,7 +4,8 @@ ========== Shows how to combine Normalization and Colormap instances to draw -"levels" in pcolor, pcolormesh and imshow type plots in a similar +"levels" in :meth:`~.axes.Axes.pcolor`, :meth:`~.axes.Axes.pcolormesh` +and :meth:`~.axes.Axes.imshow` type plots in a similar way to the levels keyword argument to contour/contourf. """ @@ -67,5 +68,10 @@ # The use of the following functions and methods is shown in this example: matplotlib.axes.Axes.pcolormesh +matplotlib.pyplot.pcolormesh matplotlib.axes.Axes.contourf +matplotlib.pyplot.contourf matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.colors.BoundaryNorm +matplotlib.ticker.MaxNLocator diff --git a/examples/images_contours_and_fields/plot_streamplot.py b/examples/images_contours_and_fields/plot_streamplot.py index bf57db9a0e33..2f577c76d421 100644 --- a/examples/images_contours_and_fields/plot_streamplot.py +++ b/examples/images_contours_and_fields/plot_streamplot.py @@ -4,7 +4,7 @@ ========== A stream plot, or streamline plot, is used to display 2D vector fields. This -example shows a few features of the streamplot function: +example shows a few features of the :meth:`~.axes.Axes.streamplot` function: * Varying the color along a streamline. * Varying the density of streamlines. @@ -71,3 +71,18 @@ plt.tight_layout() plt.show() +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown in this example: + +import matplotlib +matplotlib.axes.Axes.streamplot +matplotlib.pyplot.streamplot +matplotlib.gridspec +matplotlib.gridspec.GridSpec + diff --git a/examples/images_contours_and_fields/quadmesh_demo.py b/examples/images_contours_and_fields/quadmesh_demo.py index 0c133e34200d..0e517a886a10 100644 --- a/examples/images_contours_and_fields/quadmesh_demo.py +++ b/examples/images_contours_and_fields/quadmesh_demo.py @@ -3,8 +3,8 @@ QuadMesh Demo ============= -pcolormesh uses a QuadMesh, a faster generalization of pcolor, but -with some restrictions. +`~.axes.Axes.pcolormesh` uses a `~matplotlib.collections.QuadMesh`, +a faster generalization of `~.axes.Axes.pcolor`, but with some restrictions. This demo illustrates a bug in quadmesh with masked data. """ @@ -30,7 +30,7 @@ axs[0].pcolormesh(Qx, Qz, Z, shading='gouraud') axs[0].set_title('Without masked values') -# You can control the color of the masked region. We copy the default colormap +# You can control the color of the masked region. We copy the default colormap # before modifying it. cmap = copy.copy(cm.get_cmap(plt.rcParams['image.cmap'])) cmap.set_bad('y', 1.0) @@ -43,3 +43,16 @@ fig.tight_layout() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown in this example: + +import matplotlib +matplotlib.axes.Axes.pcolormesh +matplotlib.pyplot.pcolormesh diff --git a/examples/images_contours_and_fields/quiver_demo.py b/examples/images_contours_and_fields/quiver_demo.py index 636a046ee0d5..281a9854d130 100644 --- a/examples/images_contours_and_fields/quiver_demo.py +++ b/examples/images_contours_and_fields/quiver_demo.py @@ -3,6 +3,10 @@ Demonstration of advanced quiver and quiverkey functions ======================================================== +Demonstrates some more advanced options for `~.axes.Axes.quiver`. +For a simple example refer to +:ref:`sphx_glr_gallery_images_contours_and_fields_quiver_simple_demo.py`. + Known problem: the plot autoscaling does not take into account the arrows, so those on the boundaries are often out of the picture. This is *not* an easy problem to solve in a perfectly general way. @@ -46,3 +50,18 @@ ax3.scatter(X, Y, color='k', s=5) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown in this example: + +import matplotlib +matplotlib.axes.Axes.quiver +matplotlib.pyplot.quiver +matplotlib.axes.Axes.quiverkey +matplotlib.pyplot.quiverkey diff --git a/examples/images_contours_and_fields/quiver_simple_demo.py b/examples/images_contours_and_fields/quiver_simple_demo.py index f4df0bbcc155..39349abac095 100644 --- a/examples/images_contours_and_fields/quiver_simple_demo.py +++ b/examples/images_contours_and_fields/quiver_simple_demo.py @@ -3,7 +3,11 @@ Quiver Simple Demo ================== -A simple example of a quiver plot with a quiverkey. +A simple example of a `~.axes.Axes.quiver` plot with a +`~.axes.Axes.quiverkey`. + +For more advanced options refer to +:ref:`sphx_glr_gallery_images_contours_and_fields_quiver_demo.py`. """ import matplotlib.pyplot as plt import numpy as np @@ -18,3 +22,19 @@ label='Quiver key, length = 10', labelpos='E') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions and methods is shown in this example: + +import matplotlib +matplotlib.axes.Axes.quiver +matplotlib.pyplot.quiver +matplotlib.axes.Axes.quiverkey +matplotlib.pyplot.quiverkey + diff --git a/examples/images_contours_and_fields/shading_example.py b/examples/images_contours_and_fields/shading_example.py index ef8d171a300e..f97aa8efe12f 100644 --- a/examples/images_contours_and_fields/shading_example.py +++ b/examples/images_contours_and_fields/shading_example.py @@ -61,3 +61,17 @@ def compare(z, cmap, ve=1): if __name__ == '__main__': main() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown in this example: + +import matplotlib +matplotlib.colors.LightSource +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow diff --git a/examples/images_contours_and_fields/specgram_demo.py b/examples/images_contours_and_fields/specgram_demo.py index 681ac2ba36e6..f10f518739d6 100644 --- a/examples/images_contours_and_fields/specgram_demo.py +++ b/examples/images_contours_and_fields/specgram_demo.py @@ -3,7 +3,8 @@ Spectrogram Demo ================ -Demo of a spectrogram plot. +Demo of a spectrogram plot +(:meth:`~.axes.Axes.specgram`). """ import matplotlib.pyplot as plt import numpy as np @@ -36,3 +37,17 @@ # - bins: the centers of the time bins # - im: the matplotlib.image.AxesImage instance representing the data in the plot plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.specgram +matplotlib.pyplot.specgram diff --git a/examples/images_contours_and_fields/spy_demos.py b/examples/images_contours_and_fields/spy_demos.py index 2a518375ec6e..a24f134e407c 100644 --- a/examples/images_contours_and_fields/spy_demos.py +++ b/examples/images_contours_and_fields/spy_demos.py @@ -3,7 +3,7 @@ Spy Demos ========= -Plot the sparsity pattern of arrays +Plot the sparsity pattern of arrays. """ import matplotlib.pyplot as plt @@ -26,3 +26,17 @@ ax4.spy(x, precision=0.1) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.spy +matplotlib.pyplot.spy diff --git a/examples/images_contours_and_fields/tricontour_demo.py b/examples/images_contours_and_fields/tricontour_demo.py index 130ddfb02bcb..e39e73c12b81 100644 --- a/examples/images_contours_and_fields/tricontour_demo.py +++ b/examples/images_contours_and_fields/tricontour_demo.py @@ -110,3 +110,18 @@ ax2.set_ylabel('Latitude (degrees)') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods and classes is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.tricontourf +matplotlib.pyplot.tricontourf +matplotlib.tri.Triangulation diff --git a/examples/images_contours_and_fields/tricontour_smooth_delaunay.py b/examples/images_contours_and_fields/tricontour_smooth_delaunay.py index 0af199b2fc68..6b3566fd64d4 100644 --- a/examples/images_contours_and_fields/tricontour_smooth_delaunay.py +++ b/examples/images_contours_and_fields/tricontour_smooth_delaunay.py @@ -4,7 +4,7 @@ ========================== Demonstrates high-resolution tricontouring of a random set of points ; -a matplotlib.tri.TriAnalyzer is used to improve the plot quality. +a `matplotlib.tri.TriAnalyzer` is used to improve the plot quality. The initial data points and triangular grid for this demo are: @@ -16,12 +16,12 @@ The proposed generic procedure to obtain a high resolution contouring of such a data set is the following: -1. Compute an extended mask with a matplotlib.tri.TriAnalyzer, which will +1. Compute an extended mask with a `matplotlib.tri.TriAnalyzer`, which will exclude badly shaped (flat) triangles from the border of the triangulation. Apply the mask to the triangulation (using set_mask). 2. Refine and interpolate the data using a - matplotlib.tri.UniformTriRefiner. -3. Plot the refined data with tricontour. + `matplotlib.tri.UniformTriRefiner`. +3. Plot the refined data with `~.axes.Axes.tricontour`. """ from matplotlib.tri import Triangulation, TriAnalyzer, UniformTriRefiner @@ -137,3 +137,25 @@ def experiment_res(x, y): ax.triplot(flat_tri, color='red') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.tricontour +matplotlib.pyplot.tricontour +matplotlib.axes.Axes.tricontourf +matplotlib.pyplot.tricontourf +matplotlib.axes.Axes.triplot +matplotlib.pyplot.triplot +matplotlib.tri +matplotlib.tri.Triangulation +matplotlib.tri.TriAnalyzer +matplotlib.tri.UniformTriRefiner diff --git a/examples/images_contours_and_fields/tricontour_smooth_user.py b/examples/images_contours_and_fields/tricontour_smooth_user.py index 42b235d5543a..8ab61348107c 100644 --- a/examples/images_contours_and_fields/tricontour_smooth_user.py +++ b/examples/images_contours_and_fields/tricontour_smooth_user.py @@ -4,7 +4,7 @@ ====================== Demonstrates high-resolution tricontouring on user-defined triangular grids -with matplotlib.tri.UniformTriRefiner +with `matplotlib.tri.UniformTriRefiner`. """ import matplotlib.tri as tri import matplotlib.pyplot as plt @@ -76,3 +76,22 @@ def function_z(x, y): ax.set_title("High-resolution tricontouring") plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.tricontour +matplotlib.pyplot.tricontour +matplotlib.axes.Axes.tricontourf +matplotlib.pyplot.tricontourf +matplotlib.tri +matplotlib.tri.Triangulation +matplotlib.tri.UniformTriRefiner diff --git a/examples/images_contours_and_fields/trigradient_demo.py b/examples/images_contours_and_fields/trigradient_demo.py index 911b49402762..0f7881bebc9f 100644 --- a/examples/images_contours_and_fields/trigradient_demo.py +++ b/examples/images_contours_and_fields/trigradient_demo.py @@ -3,7 +3,8 @@ Trigradient Demo ================ -Demonstrates computation of gradient with matplotlib.tri.CubicTriInterpolator. +Demonstrates computation of gradient with +`matplotlib.tri.CubicTriInterpolator`. """ from matplotlib.tri import ( Triangulation, UniformTriRefiner, CubicTriInterpolator) @@ -85,3 +86,26 @@ def dipole_potential(x, y): ax.set_title('Gradient plot: an electrical dipole') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.tricontour +matplotlib.pyplot.tricontour +matplotlib.axes.Axes.triplot +matplotlib.pyplot.triplot +matplotlib.tri +matplotlib.tri.Triangulation +matplotlib.tri.CubicTriInterpolator +matplotlib.tri.CubicTriInterpolator.gradient +matplotlib.tri.UniformTriRefiner +matplotlib.axes.Axes.quiver +matplotlib.pyplot.quiver diff --git a/examples/images_contours_and_fields/triinterp_demo.py b/examples/images_contours_and_fields/triinterp_demo.py index 650a4b621fe1..087a2839ac11 100644 --- a/examples/images_contours_and_fields/triinterp_demo.py +++ b/examples/images_contours_and_fields/triinterp_demo.py @@ -58,3 +58,27 @@ fig.tight_layout() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.tricontourf +matplotlib.pyplot.tricontourf +matplotlib.axes.Axes.triplot +matplotlib.pyplot.triplot +matplotlib.axes.Axes.contourf +matplotlib.pyplot.contourf +matplotlib.axes.Axes.plot +matplotlib.pyplot.plot +matplotlib.tri +matplotlib.tri.LinearTriInterpolator +matplotlib.tri.CubicTriInterpolator +matplotlib.tri.Triangulation diff --git a/examples/images_contours_and_fields/tripcolor_demo.py b/examples/images_contours_and_fields/tripcolor_demo.py index 877d434ae1e1..67f638ad4364 100644 --- a/examples/images_contours_and_fields/tripcolor_demo.py +++ b/examples/images_contours_and_fields/tripcolor_demo.py @@ -124,3 +124,19 @@ ax3.set_ylabel('Latitude (degrees)') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.tripcolor +matplotlib.pyplot.tripcolor +matplotlib.tri +matplotlib.tri.Triangulation diff --git a/examples/images_contours_and_fields/triplot_demo.py b/examples/images_contours_and_fields/triplot_demo.py index 0efc7011b4a8..836848205e35 100644 --- a/examples/images_contours_and_fields/triplot_demo.py +++ b/examples/images_contours_and_fields/triplot_demo.py @@ -104,3 +104,19 @@ ax2.set_ylabel('Latitude (degrees)') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.triplot +matplotlib.pyplot.triplot +matplotlib.tri +matplotlib.tri.Triangulation diff --git a/tutorials/advanced/transforms_tutorial.py b/tutorials/advanced/transforms_tutorial.py index 8d090ae3e62a..7fd477e2bd06 100644 --- a/tutorials/advanced/transforms_tutorial.py +++ b/tutorials/advanced/transforms_tutorial.py @@ -242,7 +242,7 @@ plt.show() ############################################################################### -# .. blended_transformations: +# .. _blended_transformations: # # Blended transformations # ======================= @@ -303,7 +303,7 @@ # # trans = ax.get_xaxis_transform() # -# .. offset-transforms-shadow: +# .. _offset-transforms-shadow: # # Using offset transforms to create a shadow effect # ================================================= @@ -371,7 +371,7 @@ plt.show() ############################################################################### -# .. transformation-pipeline: +# .. _transformation-pipeline: # # The transformation pipeline # =========================== From 63b88ebb72e6acf8dacab6eddca95b3a78b9a157 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 10 May 2018 13:10:57 -0700 Subject: [PATCH 3/4] Merge pull request #11209 from ImportanceOfBeingErnest/example-refs_shapes-coll-lines DOC: Adding example references for Shapes,Pie&Polar,Color sections Conflicts: examples/pie_and_polar_charts/pie_demo2.py Removed all changes to pie_demo2.py because other changes to that example on master branch exposes bugs that are present in 2.2.2 --- examples/color/color_by_yvalue.py | 14 ++++ examples/color/color_cycle_default.py | 21 ++++- examples/color/color_cycler.py | 20 ++++- examples/color/color_demo.py | 79 ++++++++++++++----- examples/color/colorbar_basics.py | 21 ++++- examples/color/colormap_reference.py | 16 ++++ examples/color/named_colors.py | 25 ++++++ examples/pie_and_polar_charts/nested_pie.py | 19 +++++ .../pie_and_donut_labels.py | 17 ++++ examples/pie_and_polar_charts/pie_features.py | 14 ++++ examples/pie_and_polar_charts/polar_bar.py | 15 ++++ examples/pie_and_polar_charts/polar_demo.py | 18 +++++ examples/pie_and_polar_charts/polar_legend.py | 16 ++++ .../pie_and_polar_charts/polar_scatter.py | 19 +++++ .../artist_reference.py | 35 +++++++- .../shapes_and_collections/collections.py | 23 +++++- .../shapes_and_collections/compound_path.py | 22 +++++- examples/shapes_and_collections/dolphin.py | 25 +++++- examples/shapes_and_collections/donut.py | 26 +++++- .../ellipse_collection.py | 20 +++++ .../shapes_and_collections/ellipse_demo.py | 50 ++++++++++++ .../shapes_and_collections/ellipse_rotated.py | 26 ------ .../shapes_and_collections/fancybox_demo.py | 17 ++++ examples/shapes_and_collections/hatch_demo.py | 19 +++++ .../shapes_and_collections/line_collection.py | 21 ++++- .../shapes_and_collections/marker_path.py | 19 +++++ examples/shapes_and_collections/path_patch.py | 19 ++++- 27 files changed, 574 insertions(+), 62 deletions(-) delete mode 100644 examples/shapes_and_collections/ellipse_rotated.py diff --git a/examples/color/color_by_yvalue.py b/examples/color/color_by_yvalue.py index 26ffbd95091d..4c9e61a8326f 100644 --- a/examples/color/color_by_yvalue.py +++ b/examples/color/color_by_yvalue.py @@ -22,3 +22,17 @@ fig, ax = plt.subplots() ax.plot(t, smiddle, t, slower, t, supper) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.plot +matplotlib.pyplot.plot diff --git a/examples/color/color_cycle_default.py b/examples/color/color_cycle_default.py index ae887b15c2ab..d4f70a0d90df 100644 --- a/examples/color/color_cycle_default.py +++ b/examples/color/color_cycle_default.py @@ -3,7 +3,8 @@ Colors in the default property cycle ==================================== -Display the colors from the default prop_cycle. +Display the colors from the default prop_cycle, which is obtained from the +:ref:`rc parameters`. """ import numpy as np import matplotlib.pyplot as plt @@ -38,3 +39,21 @@ fig.suptitle('Colors in the default prop_cycle', fontsize='large') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.axhline +matplotlib.axes.Axes.axvline +matplotlib.pyplot.axhline +matplotlib.pyplot.axvline +matplotlib.axes.Axes.set_facecolor +matplotlib.figure.Figure.suptitle diff --git a/examples/color/color_cycler.py b/examples/color/color_cycler.py index cec1b278c886..7f18df98fac0 100644 --- a/examples/color/color_cycler.py +++ b/examples/color/color_cycler.py @@ -8,8 +8,10 @@ This example demonstrates two different APIs: - 1. Setting the default rc parameter specifying the property cycle. - This affects all subsequent axes (but not axes already created). + 1. Setting the default + :ref:`rc parameter` + specifying the property cycle. This affects all subsequent axes + (but not axes already created). 2. Setting the property cycle for a single pair of axes. """ from cycler import cycler @@ -39,3 +41,17 @@ # Tweak spacing between subplots to prevent labels from overlapping fig.subplots_adjust(hspace=0.3) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.plot +matplotlib.axes.Axes.set_prop_cycle diff --git a/examples/color/color_demo.py b/examples/color/color_demo.py index 684e4a8ddd8c..9740744f3cfe 100644 --- a/examples/color/color_demo.py +++ b/examples/color/color_demo.py @@ -3,32 +3,75 @@ Color Demo ========== -matplotlib gives you 5 ways to specify colors, +Matplotlib gives you 8 ways to specify colors, - 1) as a single letter string, ala MATLAB +1) an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g. ``(0.1, 0.2, 0.5)`` + or ``(0.1, 0.2, 0.5, 0.3)``). RGBA is short for Red, Green, Blue, Alpha; +2) a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0F0F0F0F'``); +3) a string representation of a float value in ``[0, 1]`` inclusive for gray + level (e.g., ``'0.5'``); +4) a single letter string, i.e. one of + ``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``; +5) a X11/CSS4 ("html") color name, e.g. ``"blue"``; +6) a name from the `xkcd color survey `__, + prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``); +7) a "Cn" color spec, i.e. `'C'` followed by a single digit, which is an index + into the default property cycle + (``matplotlib.rcParams['axes.prop_cycle']``); the indexing occurs at artist + creation time and defaults to black if the cycle does not include color. +8) one of ``{'tab:blue', 'tab:orange', 'tab:green', + 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', + 'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the + 'tab10' categorical palette (which is the default color cycle); - 2) as an html style hex string or html color name +For more information on colors in matplotlib see - 3) as an R,G,B tuple, where R,G,B, range from 0-1 - - 4) as a string representing a floating point number - from 0 to 1, corresponding to shades of gray. - - 5) as a special color "Cn", where n is a number 0-9 specifying the - nth color in the currently active color cycle. - -See help(colors) for more info. +* the :ref:`sphx_glr_tutorials_colors_colors.py` tutorial; +* the `matplotlib.colors` API; +* the :ref:`sphx_glr_gallery_color_named_colors.py` example. """ + import matplotlib.pyplot as plt import numpy as np -t = np.arange(0.0, 2.0, 0.01) +t = np.linspace(0.0, 2.0, 201) s = np.sin(2 * np.pi * t) -fig, ax = plt.subplots(facecolor='darkslategray') -ax.plot(t, s, 'C1') -ax.set_xlabel('time (s)', color='C1') -ax.set_ylabel('voltage (mV)', color='0.5') # grayscale color -ax.set_title('About as silly as it gets, folks', color='#afeeee') +# 1) RGB tuple: +fig, ax = plt.subplots(facecolor=(.18, .31, .31)) +# 2) hex string: +ax.set_facecolor('#eafff5') +# 3) gray level string: +ax.set_title('Voltage vs. time chart', color='0.7') +# 4) single letter color string +ax.set_xlabel('time (s)', color='c') +# 5) a named color: +ax.set_ylabel('voltage (mV)', color='peachpuff') +# 6) a named xkcd color: +ax.plot(t, s, 'xkcd:crimson') +# 7) Cn notation: +ax.plot(t, .7*s, color='C4', linestyle='--') +# 8) tab notation: +ax.tick_params(labelcolor='tab:orange') + plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.colors +matplotlib.axes.Axes.plot +matplotlib.axes.Axes.set_facecolor +matplotlib.axes.Axes.set_title +matplotlib.axes.Axes.set_xlabel +matplotlib.axes.Axes.set_ylabel +matplotlib.axes.Axes.tick_params diff --git a/examples/color/colorbar_basics.py b/examples/color/colorbar_basics.py index a3c4b8e1e420..6ba4d00477b6 100644 --- a/examples/color/colorbar_basics.py +++ b/examples/color/colorbar_basics.py @@ -3,8 +3,9 @@ Colorbar ======== -Use colorbar by specifying the mappable object (here -the imshow returned object) and the axes to attach the colorbar to. +Use `~.figure.Figure.colorbar` by specifying the mappable object (here +the `~.matplotlib.image.AxesImage` returned by `~.axes.Axes.imshow`) +and the axes to attach the colorbar to. """ import numpy as np @@ -35,3 +36,19 @@ fig.colorbar(neg, ax=ax2) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.imshow +matplotlib.pyplot.imshow +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar diff --git a/examples/color/colormap_reference.py b/examples/color/colormap_reference.py index 5927a727c09d..8e4d3d14f7ee 100644 --- a/examples/color/colormap_reference.py +++ b/examples/color/colormap_reference.py @@ -65,3 +65,19 @@ def plot_color_gradients(cmap_category, cmap_list, nrows): plot_color_gradients(cmap_category, cmap_list, nrows) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.colors +matplotlib.axes.Axes.imshow +matplotlib.figure.Figure.text +matplotlib.axes.Axes.set_axis_off diff --git a/examples/color/named_colors.py b/examples/color/named_colors.py index 5fcf95974d1c..06a3953d1d8a 100644 --- a/examples/color/named_colors.py +++ b/examples/color/named_colors.py @@ -4,6 +4,12 @@ ======================== Simple plot example with the named colors and its visual representation. + +For more information on colors in matplotlib see + +* the :ref:`sphx_glr_tutorials_colors_colors.py` tutorial; +* the `matplotlib.colors` API; +* the :ref:`sphx_glr_gallery_color_color_demo.py`. """ from __future__ import division @@ -53,3 +59,22 @@ top=1, bottom=0, hspace=0, wspace=0) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.colors +matplotlib.colors.rgb_to_hsv +matplotlib.colors.to_rgba +matplotlib.figure.Figure.get_size_inches +matplotlib.figure.Figure.subplots_adjust +matplotlib.axes.Axes.text +matplotlib.axes.Axes.hlines diff --git a/examples/pie_and_polar_charts/nested_pie.py b/examples/pie_and_polar_charts/nested_pie.py index d1a3855b9601..ce2be648f1cb 100644 --- a/examples/pie_and_polar_charts/nested_pie.py +++ b/examples/pie_and_polar_charts/nested_pie.py @@ -76,3 +76,22 @@ ax.set(title="Pie plot with `ax.bar` and polar coordinates") ax.set_axis_off() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.pie +matplotlib.pyplot.pie +matplotlib.axes.Axes.bar +matplotlib.pyplot.bar +matplotlib.projections.polar +matplotlib.axes.Axes.set +matplotlib.axes.Axes.set_axis_off diff --git a/examples/pie_and_polar_charts/pie_and_donut_labels.py b/examples/pie_and_polar_charts/pie_and_donut_labels.py index 7e6e606e8cb2..49e75606cd2c 100644 --- a/examples/pie_and_polar_charts/pie_and_donut_labels.py +++ b/examples/pie_and_polar_charts/pie_and_donut_labels.py @@ -123,3 +123,20 @@ def func(pct, allvals): # And here it is, the donut. Note however, that if we were to use this recipe, # the ingredients would suffice for around 6 donuts - producing one huge # donut is untested and might result in kitchen errors. + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.pie +matplotlib.pyplot.pie +matplotlib.axes.Axes.legend +matplotlib.pyplot.legend diff --git a/examples/pie_and_polar_charts/pie_features.py b/examples/pie_and_polar_charts/pie_features.py index 65b85b02320a..d52f3a699aee 100644 --- a/examples/pie_and_polar_charts/pie_features.py +++ b/examples/pie_and_polar_charts/pie_features.py @@ -33,3 +33,17 @@ ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle. plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.pie +matplotlib.pyplot.pie diff --git a/examples/pie_and_polar_charts/polar_bar.py b/examples/pie_and_polar_charts/polar_bar.py index 38a557ab4553..58fd07fad682 100644 --- a/examples/pie_and_polar_charts/polar_bar.py +++ b/examples/pie_and_polar_charts/polar_bar.py @@ -27,3 +27,18 @@ bar.set_alpha(0.5) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.bar +matplotlib.pyplot.bar +matplotlib.projections.polar diff --git a/examples/pie_and_polar_charts/polar_demo.py b/examples/pie_and_polar_charts/polar_demo.py index eb89d19c92cb..1ba897a9fa48 100644 --- a/examples/pie_and_polar_charts/polar_demo.py +++ b/examples/pie_and_polar_charts/polar_demo.py @@ -21,3 +21,21 @@ ax.set_title("A line plot on a polar axis", va='bottom') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.plot +matplotlib.projections.polar +matplotlib.projections.polar.PolarAxes +matplotlib.projections.polar.PolarAxes.set_rticks +matplotlib.projections.polar.PolarAxes.set_rmax +matplotlib.projections.polar.PolarAxes.set_rlabel_position diff --git a/examples/pie_and_polar_charts/polar_legend.py b/examples/pie_and_polar_charts/polar_legend.py index 4fe6b201090f..f7f58a9be17d 100644 --- a/examples/pie_and_polar_charts/polar_legend.py +++ b/examples/pie_and_polar_charts/polar_legend.py @@ -26,3 +26,19 @@ ax.legend() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.plot +matplotlib.axes.Axes.legend +matplotlib.projections.polar +matplotlib.projections.polar.PolarAxes diff --git a/examples/pie_and_polar_charts/polar_scatter.py b/examples/pie_and_polar_charts/polar_scatter.py index f3ce26b7eb9e..350369ed3557 100644 --- a/examples/pie_and_polar_charts/polar_scatter.py +++ b/examples/pie_and_polar_charts/polar_scatter.py @@ -54,3 +54,22 @@ ax.set_thetamax(135) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.scatter +matplotlib.pyplot.scatter +matplotlib.projections.polar +matplotlib.projections.polar.PolarAxes.set_rorigin +matplotlib.projections.polar.PolarAxes.set_theta_zero_location +matplotlib.projections.polar.PolarAxes.set_thetamin +matplotlib.projections.polar.PolarAxes.set_thetamax diff --git a/examples/shapes_and_collections/artist_reference.py b/examples/shapes_and_collections/artist_reference.py index 42e0c50ed7d3..d3fb7c01cec0 100644 --- a/examples/shapes_and_collections/artist_reference.py +++ b/examples/shapes_and_collections/artist_reference.py @@ -5,7 +5,7 @@ This example displays several of matplotlib's graphics primitives (artists) drawn using matplotlib API. A full list of artists and the documentation is -available at http://matplotlib.org/api/artist_api.html. +available at :ref:`the artist API `. Copyright (c) 2010, Bartosz Telenczuk BSD License @@ -18,9 +18,6 @@ from matplotlib.collections import PatchCollection -plt.rcdefaults() - - def label(xy, text): y = xy[1] - 0.15 # shift y-value for label so that it's below the artist plt.text(xy[0], y, text, ha="center", family='sans-serif', size=14) @@ -104,3 +101,33 @@ def label(xy, text): plt.tight_layout() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.lines +matplotlib.lines.Line2D +matplotlib.patches +matplotlib.patches.Circle +matplotlib.patches.Ellipse +matplotlib.patches.Wedge +matplotlib.patches.Rectangle +matplotlib.patches.Arrow +matplotlib.patches.PathPatch +matplotlib.patches.FancyBboxPatch +matplotlib.patches.RegularPolygon +matplotlib.collections +matplotlib.collections.PatchCollection +matplotlib.cm.ScalarMappable.set_array +matplotlib.axes.Axes.add_collection +matplotlib.axes.Axes.add_line diff --git a/examples/shapes_and_collections/collections.py b/examples/shapes_and_collections/collections.py index b12b6f853c7a..853d95ff35f3 100644 --- a/examples/shapes_and_collections/collections.py +++ b/examples/shapes_and_collections/collections.py @@ -6,7 +6,8 @@ For the first two subplots, we will use spirals. Their size will be set in plot units, not data units. Their positions will be set in data units by using the "offsets" and "transOffset" -kwargs of the LineCollection and PolyCollection. +kwargs of the `~.collections.LineCollection` and +`~.collections.PolyCollection`. The third subplot will make regular polygons, with the same type of scaling and positioning as in the first two. @@ -125,3 +126,23 @@ plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.figure.Figure +matplotlib.collections +matplotlib.collections.LineCollection +matplotlib.collections.RegularPolyCollection +matplotlib.axes.Axes.add_collection +matplotlib.axes.Axes.autoscale_view +matplotlib.transforms.Affine2D +matplotlib.transforms.Affine2D.scale diff --git a/examples/shapes_and_collections/compound_path.py b/examples/shapes_and_collections/compound_path.py index 25dc23da6ad6..5667f494001d 100644 --- a/examples/shapes_and_collections/compound_path.py +++ b/examples/shapes_and_collections/compound_path.py @@ -4,7 +4,7 @@ ============= Make a compound path -- in this case two simple polygons, a rectangle -and a triangle. Use CLOSEPOLY and MOVETO for the different parts of +and a triangle. Use ``CLOSEPOLY`` and ``MOVETO`` for the different parts of the compound path """ import numpy as np @@ -31,8 +31,24 @@ ax.add_patch(pathpatch) ax.set_title('A compound path') -ax.dataLim.update_from_data_xy(vertices) ax.autoscale_view() - plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.patches +matplotlib.patches.PathPatch +matplotlib.axes.Axes.add_patch +matplotlib.axes.Axes.autoscale_view diff --git a/examples/shapes_and_collections/dolphin.py b/examples/shapes_and_collections/dolphin.py index d50b5f61726c..90d48469f426 100644 --- a/examples/shapes_and_collections/dolphin.py +++ b/examples/shapes_and_collections/dolphin.py @@ -4,8 +4,8 @@ ======== This example shows how to draw, and manipulate shapes given vertices -and nodes using the `Patches`, `Path` and `Transforms` classes. - +and nodes using the `~.path.Path`, `~.patches.PathPatch` and +`~matplotlib.transforms` classes. """ import matplotlib.cm as cm @@ -101,3 +101,24 @@ ax.add_patch(dolphin_patch2) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.patches +matplotlib.patches.PathPatch +matplotlib.patches.Circle +matplotlib.axes.Axes.add_patch +matplotlib.transforms +matplotlib.transforms.Affine2D +matplotlib.transforms.Affine2D.rotate_deg diff --git a/examples/shapes_and_collections/donut.py b/examples/shapes_and_collections/donut.py index fca5ff6a91fb..794cd342b039 100644 --- a/examples/shapes_and_collections/donut.py +++ b/examples/shapes_and_collections/donut.py @@ -3,7 +3,8 @@ Mmh Donuts!!! ============= -Draw donuts (miam!) using Path and Patches. +Draw donuts (miam!) using `~.path.Path`\s and `~.patches.PathPatch`\es. +This example shows the effect of the path's orientations in a compound path. """ import numpy as np @@ -60,3 +61,26 @@ def make_circle(r): ax.set_title('Mmm, donuts!') ax.set_aspect(1.0) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.patches +matplotlib.patches.PathPatch +matplotlib.patches.Circle +matplotlib.axes.Axes.add_patch +matplotlib.axes.Axes.annotate +matplotlib.axes.Axes.set_aspect +matplotlib.axes.Axes.set_xlim +matplotlib.axes.Axes.set_ylim +matplotlib.axes.Axes.set_title diff --git a/examples/shapes_and_collections/ellipse_collection.py b/examples/shapes_and_collections/ellipse_collection.py index 0ca477255b2e..9dbcd845cf67 100644 --- a/examples/shapes_and_collections/ellipse_collection.py +++ b/examples/shapes_and_collections/ellipse_collection.py @@ -3,6 +3,9 @@ Ellipse Collection ================== +Drawing a collection of ellipses. While this would equally be possible using +a `~.collections.EllipseCollection` or `~.collections.PathCollection`, the use +of an `~.collections.EllipseCollection` allows for much shorter code. """ import matplotlib.pyplot as plt import numpy as np @@ -31,3 +34,20 @@ cbar = plt.colorbar(ec) cbar.set_label('X+Y') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.collections +matplotlib.collections.EllipseCollection +matplotlib.axes.Axes.add_collection +matplotlib.axes.Axes.autoscale_view +matplotlib.cm.ScalarMappable.set_array diff --git a/examples/shapes_and_collections/ellipse_demo.py b/examples/shapes_and_collections/ellipse_demo.py index 3fd33d9afdf0..21fbe7d9c0e5 100644 --- a/examples/shapes_and_collections/ellipse_demo.py +++ b/examples/shapes_and_collections/ellipse_demo.py @@ -3,6 +3,9 @@ Ellipse Demo ============ +Draw many ellipses. Here individual ellipses are drawn. Compare this +to the :ref:`Ellipse collection example +`. """ import matplotlib.pyplot as plt import numpy as np @@ -26,3 +29,50 @@ ax.set_ylim(0, 10) plt.show() + +############################################################################# +# =============== +# Ellipse Rotated +# =============== +# +# Draw many ellipses with different angles. +# + +import matplotlib.pyplot as plt +import numpy as np +from matplotlib.patches import Ellipse + +delta = 45.0 # degrees + +angles = np.arange(0, 360 + delta, delta) +ells = [Ellipse((1, 1), 4, 2, a) for a in angles] + +a = plt.subplot(111, aspect='equal') + +for e in ells: + e.set_clip_box(a.bbox) + e.set_alpha(0.1) + a.add_artist(e) + +plt.xlim(-2, 4) +plt.ylim(-1, 3) + +plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.patches +matplotlib.patches.Ellipse +matplotlib.axes.Axes.add_artist +matplotlib.artist.Artist.set_clip_box +matplotlib.artist.Artist.set_alpha +matplotlib.patches.Patch.set_facecolor diff --git a/examples/shapes_and_collections/ellipse_rotated.py b/examples/shapes_and_collections/ellipse_rotated.py deleted file mode 100644 index 3bf7e8f57c86..000000000000 --- a/examples/shapes_and_collections/ellipse_rotated.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -=============== -Ellipse Rotated -=============== - -""" -import matplotlib.pyplot as plt -import numpy as np -from matplotlib.patches import Ellipse - -delta = 45.0 # degrees - -angles = np.arange(0, 360 + delta, delta) -ells = [Ellipse((1, 1), 4, 2, a) for a in angles] - -a = plt.subplot(111, aspect='equal') - -for e in ells: - e.set_clip_box(a.bbox) - e.set_alpha(0.1) - a.add_artist(e) - -plt.xlim(-2, 4) -plt.ylim(-1, 3) - -plt.show() diff --git a/examples/shapes_and_collections/fancybox_demo.py b/examples/shapes_and_collections/fancybox_demo.py index e1dc1eb451e0..60415ef8db58 100644 --- a/examples/shapes_and_collections/fancybox_demo.py +++ b/examples/shapes_and_collections/fancybox_demo.py @@ -194,3 +194,20 @@ def test_all(): test_all() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.patches +matplotlib.patches.FancyBboxPatch +matplotlib.patches.BoxStyle +matplotlib.patches.BoxStyle.get_styles +matplotlib.transforms.Bbox diff --git a/examples/shapes_and_collections/hatch_demo.py b/examples/shapes_and_collections/hatch_demo.py index 4379d13839a7..66ea648f60d7 100644 --- a/examples/shapes_and_collections/hatch_demo.py +++ b/examples/shapes_and_collections/hatch_demo.py @@ -33,3 +33,22 @@ ax3.set_ylim((0, 2.5)) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.patches +matplotlib.patches.Ellipse +matplotlib.patches.Polygon +matplotlib.axes.Axes.add_patch +matplotlib.patches.Patch.set_hatch +matplotlib.axes.Axes.bar +matplotlib.pyplot.bar diff --git a/examples/shapes_and_collections/line_collection.py b/examples/shapes_and_collections/line_collection.py index b57ce525c389..e7dd201213b2 100644 --- a/examples/shapes_and_collections/line_collection.py +++ b/examples/shapes_and_collections/line_collection.py @@ -5,7 +5,7 @@ Plotting lines with Matplotlib. -:class:`matplotlib.collections.LineCollection` allows one to plot multiple +:class:`~matplotlib.collections.LineCollection` allows one to plot multiple lines on a figure. Below we show off some of its properties. """ import matplotlib.pyplot as plt @@ -82,3 +82,22 @@ ax.set_title('Line Collection with mapped colors') plt.sci(line_segments) # This allows interactive changing of the colormap. plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.collections +matplotlib.collections.LineCollection +matplotlib.cm.ScalarMappable.set_array +matplotlib.axes.Axes.add_collection +matplotlib.figure.Figure.colorbar +matplotlib.pyplot.colorbar +matplotlib.pyplot.sci diff --git a/examples/shapes_and_collections/marker_path.py b/examples/shapes_and_collections/marker_path.py index 12eec947b3a5..7d43df365b32 100644 --- a/examples/shapes_and_collections/marker_path.py +++ b/examples/shapes_and_collections/marker_path.py @@ -3,6 +3,7 @@ Marker Path =========== +Using a `~.path.Path` as marker for a `~.axes.Axes.plot`. """ import matplotlib.pyplot as plt import matplotlib.path as mpath @@ -20,3 +21,21 @@ plt.plot(np.arange(10)**2, '--r', marker=cut_star, markersize=15) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.path.Path.unit_regular_star +matplotlib.path.Path.unit_circle +matplotlib.axes.Axes.plot +matplotlib.pyplot.plot diff --git a/examples/shapes_and_collections/path_patch.py b/examples/shapes_and_collections/path_patch.py index dc07c2a5b004..16b1dceea70e 100644 --- a/examples/shapes_and_collections/path_patch.py +++ b/examples/shapes_and_collections/path_patch.py @@ -3,7 +3,7 @@ PathPatch object ================ -This example shows how to create `Path`\s and `PathPatch` objects through +This example shows how to create `~.path.Path` and `~.patches.PathPatch` objects through Matplotlib's API. """ import matplotlib.path as mpath @@ -37,3 +37,20 @@ ax.grid() ax.axis('equal') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.patches +matplotlib.patches.PathPatch +matplotlib.axes.Axes.add_patch From 3e784a852e3829126decf1746d9f51e8fb836f61 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 28 Jun 2018 18:44:06 -0400 Subject: [PATCH 4/4] STY: strip trailing whitespace --- examples/color/color_cycler.py | 2 +- examples/images_contours_and_fields/barb_demo.py | 1 - examples/images_contours_and_fields/contour_image.py | 2 +- examples/images_contours_and_fields/image_masked.py | 1 - examples/images_contours_and_fields/pcolor_demo.py | 2 +- examples/images_contours_and_fields/plot_streamplot.py | 1 - examples/images_contours_and_fields/quiver_demo.py | 4 ++-- examples/images_contours_and_fields/quiver_simple_demo.py | 3 +-- 8 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/color/color_cycler.py b/examples/color/color_cycler.py index 7f18df98fac0..b5037bc9adb4 100644 --- a/examples/color/color_cycler.py +++ b/examples/color/color_cycler.py @@ -8,7 +8,7 @@ This example demonstrates two different APIs: - 1. Setting the default + 1. Setting the default :ref:`rc parameter` specifying the property cycle. This affects all subsequent axes (but not axes already created). diff --git a/examples/images_contours_and_fields/barb_demo.py b/examples/images_contours_and_fields/barb_demo.py index 00331d64a703..950acc281fd0 100644 --- a/examples/images_contours_and_fields/barb_demo.py +++ b/examples/images_contours_and_fields/barb_demo.py @@ -65,4 +65,3 @@ import matplotlib matplotlib.axes.Axes.barbs matplotlib.pyplot.barbs - diff --git a/examples/images_contours_and_fields/contour_image.py b/examples/images_contours_and_fields/contour_image.py index 9bfe4d9fe546..d1e088bc5f25 100644 --- a/examples/images_contours_and_fields/contour_image.py +++ b/examples/images_contours_and_fields/contour_image.py @@ -10,7 +10,7 @@ The emphasis in this demo is on showing how to make contours register correctly on images, and on how to get both of them oriented as -desired. In particular, note the usage of the +desired. In particular, note the usage of the :ref:`"origin" and "extent" ` keyword arguments to imshow and contour. diff --git a/examples/images_contours_and_fields/image_masked.py b/examples/images_contours_and_fields/image_masked.py index af718c8536b7..b8f13c5726c8 100644 --- a/examples/images_contours_and_fields/image_masked.py +++ b/examples/images_contours_and_fields/image_masked.py @@ -91,4 +91,3 @@ matplotlib.pyplot.colorbar matplotlib.colors.BoundaryNorm matplotlib.colorbar.ColorbarBase.set_label - diff --git a/examples/images_contours_and_fields/pcolor_demo.py b/examples/images_contours_and_fields/pcolor_demo.py index 551b3238d145..2ddc0f3b5a4d 100644 --- a/examples/images_contours_and_fields/pcolor_demo.py +++ b/examples/images_contours_and_fields/pcolor_demo.py @@ -6,7 +6,7 @@ Generating images with :meth:`~.axes.Axes.pcolor`. Pcolor allows you to generate 2-D image-style plots. Below we will show how -to do so in Matplotlib. +to do so in Matplotlib. """ import matplotlib.pyplot as plt import numpy as np diff --git a/examples/images_contours_and_fields/plot_streamplot.py b/examples/images_contours_and_fields/plot_streamplot.py index 2f577c76d421..5f142899c86e 100644 --- a/examples/images_contours_and_fields/plot_streamplot.py +++ b/examples/images_contours_and_fields/plot_streamplot.py @@ -85,4 +85,3 @@ matplotlib.pyplot.streamplot matplotlib.gridspec matplotlib.gridspec.GridSpec - diff --git a/examples/images_contours_and_fields/quiver_demo.py b/examples/images_contours_and_fields/quiver_demo.py index 281a9854d130..4d0cfb0450d9 100644 --- a/examples/images_contours_and_fields/quiver_demo.py +++ b/examples/images_contours_and_fields/quiver_demo.py @@ -3,8 +3,8 @@ Demonstration of advanced quiver and quiverkey functions ======================================================== -Demonstrates some more advanced options for `~.axes.Axes.quiver`. -For a simple example refer to +Demonstrates some more advanced options for `~.axes.Axes.quiver`. +For a simple example refer to :ref:`sphx_glr_gallery_images_contours_and_fields_quiver_simple_demo.py`. Known problem: the plot autoscaling does not take into account diff --git a/examples/images_contours_and_fields/quiver_simple_demo.py b/examples/images_contours_and_fields/quiver_simple_demo.py index 39349abac095..9c7e3644de1a 100644 --- a/examples/images_contours_and_fields/quiver_simple_demo.py +++ b/examples/images_contours_and_fields/quiver_simple_demo.py @@ -6,7 +6,7 @@ A simple example of a `~.axes.Axes.quiver` plot with a `~.axes.Axes.quiverkey`. -For more advanced options refer to +For more advanced options refer to :ref:`sphx_glr_gallery_images_contours_and_fields_quiver_demo.py`. """ import matplotlib.pyplot as plt @@ -37,4 +37,3 @@ matplotlib.pyplot.quiver matplotlib.axes.Axes.quiverkey matplotlib.pyplot.quiverkey -