|
70 | 70 | # Interactive environments
|
71 | 71 | # ------------------------
|
72 | 72 | #
|
73 |
| -# The Matplotlib community suggests using `IPython<https://ipython.org/>`_ as |
| 73 | +# The Matplotlib community suggests using `IPython <https://ipython.org/>`_ as |
74 | 74 | # the primary interactive environment.
|
75 | 75 |
|
76 | 76 | ##############################################################################
|
|
80 | 80 | #
|
81 | 81 | # The common conventions for preparing to plot data involve importing the
|
82 | 82 | # necessary libraries with abbreviations for convenience. Both stateful and
|
83 |
| -# stateless programming require the |
84 |
| -# following. |
| 83 | +# stateless programming require the following. |
85 | 84 |
|
86 | 85 | import matplotlib.pyplot as plt
|
87 | 86 |
|
| 87 | +############################################################################## |
| 88 | +# |
88 | 89 | # The `pyplot` module in Matplotlib is a collection of functions. The module's
|
89 | 90 | # functions create, manage, and manipulate the current figure and the plotting
|
90 |
| -# area. NumPy is another scientific library for Python. |
91 |
| - |
| 91 | +# area. |
| 92 | +# |
92 | 93 | # These are the two common strategies for creating plots with Matplotlib.
|
93 | 94 | # - Stateful: The programming is designed to remember preceding events or
|
94 |
| -# interactions. Matplotlib automatically manages figures and ax(es). |
| 95 | +# interactions. Matplotlib automatically manages figures and axes. |
95 | 96 | # - `pyplot`, most similar to MATLAB and convenient for interactive
|
96 | 97 | # environments.
|
97 | 98 | # - Stateless: Code has explicit references to objects. Users create objects
|
98 |
| -# for specific figures and ax(es) and call on methods for manipulating data. |
99 |
| -# - Object-oriented programming, robust control and useful for generalized |
100 |
| -# code. |
101 |
| - |
| 99 | +# for specific figures and axes and call on methods for manipulating data. |
| 100 | +# - Object-oriented programming (OOP), robust control and useful for |
| 101 | +# generalized code. |
| 102 | +# |
102 | 103 | # .. note::
|
103 | 104 | #
|
104 | 105 | # The Matplotlib community does not recommend interchanging stateful and
|
|
108 | 109 | #
|
109 | 110 | # For other techniques of creating plots with Matplotlib, refer to
|
110 | 111 | # """insert reference""".
|
111 |
| - |
| 112 | +# |
| 113 | +# Data |
| 114 | +# ---- |
| 115 | +# |
112 | 116 | # The Matplotlib library manages data in the form of iterables and/or
|
113 | 117 | # sequenced items. These can also take the form of NumPy arrays like
|
114 | 118 | # `numpy.array` or `numpy.ma.masked_array`. All plotting functions take these
|
|
130 | 134 | svg_acct_10 = [1550, 1600, 1650, 1700, 1750, 1800,
|
131 | 135 | 1850, 1900, 1950, 2000, 2050, 2100]
|
132 | 136 |
|
| 137 | +############################################################################## |
| 138 | +# |
133 | 139 | # .. note::
|
134 | 140 | #
|
135 | 141 | # Other containers, such as `pandas` data objects, may not work as intended.
|
|
158 | 164 | plt.title("Personal Financial Tracking from 2009")
|
159 | 165 | plt.legend()
|
160 | 166 |
|
161 |
| -# Stateless: Object Oriented Programming |
162 |
| -# -------------------------------------- |
| 167 | +############################################################################## |
| 168 | +# |
| 169 | +# Stateless: Object Oriented Programming (OOP) |
| 170 | +# -------------------------------------------- |
163 | 171 | #
|
164 | 172 | # To use stateless programming for Matplotlib involves using a single
|
165 | 173 | # instance of the `pyplot` module to unpack the explicit figure(s) and
|
166 | 174 | # ax(es). Each axes has its own methods to plot data. Also, each axes
|
167 | 175 | # also uses separate methods to create and manage parts of a figure.
|
168 | 176 |
|
169 |
| -"""Stateless programming with Object Oriented Programming""" |
| 177 | +"""Stateless programming with OOP""" |
170 | 178 |
|
171 | 179 | y4 = chk_acct_10
|
172 | 180 | y5 = svg_acct_10
|
173 | 181 |
|
174 |
| -fig, ax = plt.subplots() # Figure & axes unpacked separately w/ module. |
| 182 | +fig, ax = plt.subplots() # Figure & axes unpacked separately with module. |
175 | 183 |
|
176 | 184 | ax.plot(x, y1, label='Checking Account')
|
177 | 185 | ax.plot(x, y4, label='Savings Account')
|
|
0 commit comments