8000 Merge pull request #7439 from NelleV/MEP12_api · matplotlib/matplotlib@a07af2d · GitHub
[go: up one dir, main page]

Skip to content

Commit a07af2d

Browse files
authored
Merge pull request #7439 from NelleV/MEP12_api
DOC: MEP12 API examples
2 parents 660aa65 + e00ee31 commit a07af2d

39 files changed

+240
-31
lines changed

examples/api/agg_oo.py

Lines changed: 4 additions & 628C ; 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- noplot -*-
22
"""
3+
=============================
4+
The object-oriented interface
5+
=============================
6+
37
A pure OO (look Ma, no pylab!) example using the agg backend
48
"""
59
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

examples/api/barchart_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
========
3+
Barchart
4+
========
5+
26
A bar plot with errorbars and height labels on individual bars
37
"""
48
import numpy as np

examples/api/bbox_intersect.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
===========================================
3+
Changing colors of lines intersecting a box
4+
===========================================
5+
6+
The lines intersecting the rectangle are colored in red, while the others
7+
are left as blue lines. This example showcases the `intersect_bbox` function.
8+
9+
"""
10+
111
import numpy as np
212
import matplotlib.pyplot as plt
313
from matplotlib.transforms import Bbox

examples/api/collections_demo.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
'''Demonstration of LineCollection, PolyCollection, and
2-
RegularPolyCollection with autoscaling.
1+
'''
2+
=========================================================
3+
Line, Poly and RegularPoly Collection with autoscaling
4+
=========================================================
35
46
For the first two subplots, we will use spirals. Their
57
size will be set in plot units, not data units. Their positions

examples/api/colorbar_basics.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
========
3+
Colorbar
4+
========
5+
6+
This example shows how to use colorbar by specifying the mappable object (here
7+
the imshow returned object) and the axes to attach the colorbar to.
8+
"""
9+
110
import numpy as np
211
import matplotlib.pyplot as plt
312

examples/api/colorbar_only.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'''
2-
Make a colorbar as a separate figure.
2+
====================
3+
Customized colorbars
4+
====================
5+
6+
This example shows how to build colorbars without an attached mappable.
37
'''
48

59
import matplotlib.pyplot as plt

examples/api/compound_path.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"""
2-
Make a compund path -- in this case two simple polygons, a rectangle
3-
and a triangle. Use CLOSEOPOLY and MOVETO for the different parts of
2+
=============
3+
Compound path
4+
=============
5+
6+
Make a compound path -- in this case two simple polygons, a rectangle
7+
and a triangle. Use CLOSEPOLY and MOVETO for the different parts of
48
the compound path
59
"""
610
import numpy as np

examples/api/custom_projection_example.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
=================
3+
Custom projection
4+
=================
5+
6+
This example showcases the Hammer projection by alleviating many features of
7+
matplotlib.
8+
"""
9+
10+
111
from __future__ import unicode_literals
212

313
import matplotlib

examples/api/custom_scale_example.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
============
3+
Custom scale
4+
============
5+
6+
This example showcases how to create a custom scale, by implementing the
7+
scaling use for latitude data in a Mercator Projection.
8+
"""
9+
10+
111
from __future__ import unicode_literals
212

313
import numpy as np

examples/api/date_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
================
3+
Date tick labels
4+
================
5+
26
Show how to make date plots in matplotlib using date tick locators and
37
formatters. See major_minor_demo1.py for more information on
48
controlling major and minor ticks

examples/api/date_index_formatter.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"""
2+
=====================================
3+
Custom tick formatter for time series
4+
=====================================
5+
26
When plotting time series, e.g., financial time series, one often wants
3-
to leave out days on which there is no data, eh weekends. The example
7+
to leave out days on which there is no data, i.e. weekends. The example
48
below shows how to use an 'index formatter' to achieve the desired plot
59
"""
610
from __future__ import print_function
@@ -19,8 +23,10 @@
1923

2024

2125
# first we'll do it the default way, with gaps on weekends
22-
fig, ax = plt.subplots()
26+
fig, axes = plt.subplots(ncols=2, figsize=(8, 4))
27+
ax = axes[0]
2328
ax.plot(r.date, r.adj_close, 'o-')
29+
ax.set_title("Default")
2430
fig.autofmt_xdate()
2531

2632
# next we'll write a custom formatter
@@ -32,9 +38,10 @@ def format_date(x, pos=None):
3238
thisind = np.clip(int(x + 0.5), 0, N - 1)
3339
return r.date[thisind].strftime('%Y-%m-%d')
3440

35-
fig, ax = plt.subplots()
41+
ax = axes[1]
3642
ax.plot(ind, r.adj_close, 'o-')
3743
ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
44+
ax.set_title("Custom tick formatter")
3845
fig.autofmt_xdate()
3946

4047
plt.show()

examples/api/demo_affine_image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
============================
3+
Affine transform of an image
4+
============================
5+
26
For the backends that support draw_image with optional affine
37
transform (e.g., agg, ps backend), the image of the output should
48
have its boundary match the dashed yellow rectangle.

examples/api/donut_demo.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
=============
3+
Mmh Donuts!!!
4+
=============
5+
6+
This example draws donuts (miam!) using Path and Patches.
7+
"""
8+
19
import numpy as np
210
import matplotlib.path as mpath
311
import matplotlib.patches as mpatches

examples/api/engineering_formatter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
'''
2+
=========================================
3+
Labeling ticks using engineering notation
4+
=========================================
5+
26
Demo to show use of the engineering Formatter.
37
'''
48

examples/api/filled_step.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
=========================
3+
Hatch-filled histograms
4+
=========================
5+
6+
This example showcases the hatching capabilities of matplotlib by plotting
7+
various histograms.
8+
"""
9+
110
import itertools
211
from collections import OrderedDict
312
from functools import partial

examples/api/font_family_rc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
===========================
3+
Configuring the font family
4+
===========================
5+
26
You can explicitly set which font family is picked up for a given font
37
style (e.g., 'serif', 'sans-serif', or 'monospace').
48

examples/api/font_file.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- noplot -*-
22
"""
3+
===================================
4+
Using a ttf font file in matplotlib
5+
===================================
6+
37
Although it is usually not a good idea to explicitly point to a single
48
ttf file for a font instance, you can do so using the
59
font_manager.FontProperties fname argument (for a more flexible

examples/api/histogram_path_demo.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
========================================================
3+
Building histograms using Rectangles and PolyCollections
4+
========================================================
5+
26
This example shows how to use a path patch to draw a bunch of
37
rectangles. The technique of using lots of Rectangle instances, or
48
the faster method of using PolyCollections, were implemented before we
@@ -41,7 +45,7 @@
4145
barpath = path.Path.make_compound_path_from_polys(XY)
4246

4347
# make a patch out of it
44-
patch = patches.PathPatch(barpath, facecolor='blue')
48+
patch = patches.PathPatch(barpath)
4549
ax.add_patch(patch)
4650

4751
# update the view limits

examples/api/image_zcoord.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
"""
2+
==================================
3+
Modifying the coordinate formatter
4+
==================================
5+
26
Show how to modify the coordinate formatter to report the image "z"
37
value of the nearest pixel given x and y
48
"""
59
import numpy as np
610
import matplotlib.pyplot as plt
7-
import matplotlib.cm as cm
811

912
# Fixing random state for reproducibility
1013
np.random.seed(19680801)

examples/api/joinstyle.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
===========
3+
Join styles
4+
===========
5+
26
Illustrate the three different join styles
37
"""
48

examples/api/legend_demo.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
===============================
3+
Legend using pre-defined labels
4+
===============================
5+
6+
Notice how the legend labels are defined with the plots!
7+
"""
8+
9+
110
import numpy as np
211
import matplotlib.pyplot as plt
312

examples/api/line_with_text.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
=======================
3+
Artist within an artist
4+
=======================
5+
26
Show how to override basic methods so an artist can contain another
37
artist. In this case, the line contains a Text instance to label it.
48
"""

examples/api/logo2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
==========
3+
matplotlib
4+
==========
5+
26
Thanks to Tony Yu <tsyu80@gmail.com> for the logo design
37
"""
48

@@ -13,7 +17,6 @@
1317

1418

1519
axalpha = 0.05
16-
#figcolor = '#EFEFEF'
1720
figcolor = 'white'
1821
dpi = 80
1922
fig = plt.figure(figsize=(6, 1.1), dpi=dpi)
@@ -37,8 +40,6 @@ def add_math_background():
3740
(0.35, 0.9), 20))
3841
text.append((r"$\int_{-\infty}^\infty e^{-x^2}dx=\sqrt{\pi}$",
3942
(0.15, 0.3), 25))
40-
#text.append((r"$E = mc^2 = \sqrt{{m_0}^2c^4 + p^2c^2}$",
41-
# (0.7, 0.42), 30))
4243
text.append((r"$F_G = G\frac{m_1m_2}{r^2}$",
4344
(0.85, 0.7), 30))
4445
for eq, (x, y), size in text:
@@ -80,6 +81,7 @@ def add_polar_bar():
8081
ax.set_yticks(np.arange(1, 9, 2))
8182
ax.set_rmax(9)
8283

84+
8385
if __name__ == '__main__':
8486
main_axes = add_math_background()
8587
add_polar_bar()

examples/api/mathtext_asarray.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
2-
Load a mathtext image as numpy array
2+
===============================
3+
A mathtext image as numpy array
4+
===============================
5+
6+
This example shows how to make images from LaTeX strings.
37
"""
48

59
import matplotlib.mathtext as mathtext

examples/api/patch_collection.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
"""
2+
============================
3+
Circles, Wedges and Polygons
4+
============================
5+
"""
6+
17
import numpy as np
28
import matplotlib
39
from matplotlib.patches import Circle, Wedge, Polygon

examples/api/power_norm_demo.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
========================
3+
Exploring normalizations
4+
========================
5+
6+
Let's explore various normalization on a multivariate normal distribution.
7+
8+
"""
9+
110
from matplotlib import pyplot as plt
211
import matplotlib.colors as mcolors
312
import numpy as np

examples/api/quad_bezier.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
============
3+
Bezier Curve
4+
============
5+
6+
This example showcases the PathPatch object to create a Bezier polycurve path
7+
patch.
8+
"""
9+
110
import matplotlib.path as mpath
211
import matplotlib.patches as mpatches
312
import matplotlib.pyplot as plt

examples/api/radar_chart.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""
2-
Example of creating a radar chart (a.k.a. a spider or star chart) [1]_.
2+
======================================
3+
Radar chart (aka spider or star chart)
4+
======================================
5+
6+
This example creates a radar chart, also known as a spider or star chart [1]_.
37
48
Although this example allows a frame of either 'circle' or 'polygon', polygon
59
frames don't have proper gridlines (the lines are circles instead of polygons).
@@ -187,7 +191,8 @@ def example_data():
187191
# add legend relative to top-left plot
188192
ax = axes[0, 0]
189193
labels = ('Factor 1', 'Factor 2', 'Factor 3', 'Factor 4', 'Factor 5')
190-
legend = ax.legend(labels, loc=(0.9, .95), labelspacing=0.1, fontsize='small')
194+
legend = ax.legend(labels, loc=(0.9, .95),
195+
labelspacing=0.1, fontsize='small')
191196

192197
fig.text(0.5, 0.965, '5-Factor Solution Profiles Across Four Scenarios',
193198
horizontalalignment='center', color='black', weight='bold',

examples/api/sankey_demo_basics.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
"""Demonstrate the Sankey class by producing three basic diagrams.
1+
"""
2+
================
3+
The Sankey class
4+
================
5+
6+
Demonstrate the Sankey class by producing three basic diagrams.
27
"""
38
import numpy as np
49
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)
0