|
22 | 22 | #
|
23 | 23 | # There are two main ways of producing plots with Matplotlib, stateful and
|
24 | 24 | # stateless. Stateful code, using `pyplot`, or stateless code, using Object
|
25 |
| -# Oriented Programming (OOP), are the foundation for |
26 |
| -# creating and manipulating data into visualizations. |
| 25 | +# Oriented Programming (OOP), are the foundation for creating and manipulating |
| 26 | +# data into visualizations. |
27 | 27 | #
|
28 | 28 | # The stateful `pyplot` approach to generate plots is simple. It is helpful
|
29 | 29 | # for basic plots and for interactive environments, such as Jupyter Notebooks.
|
|
119 | 119 | # data structures.
|
120 | 120 | #
|
121 | 121 |
|
122 |
| -"""Sample Data""" |
| 122 | +# Sample Data |
123 | 123 |
|
124 | 124 | months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
125 | 125 | 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
126 |
| -income = [950, 950, 950, 950, 950, 950, 950, 950, |
127 |
| - 950, 950, 950, 950] |
| 126 | +income = [950, 950, 950, 950, 950, 950, |
| 127 | + 950, 950, 950, 950, 950, 950] |
128 | 128 | chk_acct_09 = [1250, 1325, 1200, 1220, 1100, 1055,
|
129 | 129 | 1255, 1090, 1190, 1205, 1205, 1180]
|
130 | 130 | svg_acct_09 = [1000, 1050, 1100, 1150, 1200, 1250,
|
|
138 | 138 | #
|
139 | 139 | # .. note::
|
140 | 140 | #
|
141 |
| -# Other containers, such as `pandas` data objects, may not work as intended. |
| 141 | +# Other containers, such as `pandas` data objects, may not work as intended. |
142 | 142 | #
|
143 | 143 | # Stateful: `pyplot`
|
144 | 144 | # ------------------
|
|
149 | 149 | # Additional parts of the figure are also available through the module
|
150 | 150 | # methods.
|
151 | 151 |
|
152 |
| -"""Stateful programming with pyplot""" |
| 152 | +# Stateful programming with pyplot |
153 | 153 |
|
154 | 154 | x = months
|
155 | 155 | y1 = income
|
|
166 | 166 |
|
167 | 167 | ##############################################################################
|
168 | 168 | #
|
| 169 | +# In the example above, the `pyplot` module contains its own methods of |
| 170 | +# actionable tasks for the data. The `plt.plot` plots data as a line graph |
| 171 | +# with various keyword arguments as additional customizations. The module also |
| 172 | +# includes other methods for generating parts of the visualization. These parts |
| 173 | +# use different methods from the OOP approach. |
| 174 | +# |
169 | 175 | # Stateless: Object Oriented Programming (OOP)
|
170 | 176 | # --------------------------------------------
|
171 | 177 | #
|
172 |
| -# To use stateless programming for Matplotlib involves using a single |
173 |
| -# instance of the `pyplot` module to unpack the explicit figure(s) and |
174 |
| -# ax(es). Each axes has its own methods to plot data. Also, each axes |
175 |
| -# also uses separate methods to create and manage parts of a figure. |
| 178 | +# To use stateless programming for Matplotlib involves using a single instance |
| 179 | +# of the `pyplot` module to unpack a set or sets of explicit figure and axes. |
| 180 | +# Each axes has its own methods to plot data. In addition, each axes also |
| 181 | +# uses separate methods to create and manage parts of a figure. These methods |
| 182 | +# are different from those using stateful programming. |
176 | 183 |
|
177 |
| -"""Stateless programming with OOP""" |
| 184 | +# Stateless programming with OOP |
178 | 185 |
|
179 | 186 | y4 = chk_acct_10
|
180 | 187 | y5 = svg_acct_10
|
|
191 | 198 |
|
192 | 199 | ##############################################################################
|
193 | 200 | #
|
194 |
| -# Customizations |
195 |
| -# ============== |
| 201 | +# For the OOP example, the figure and axes are unpacked from the module using |
| 202 | +# a single instance of `pyplot`. This convention uses `plt.subplots()` and |
| 203 | +# defaults to one figure,`fig`, and one axes, `ax`. The section below on |
| 204 | +# customizations contains additional information about multiple visulizations |
| 205 | +# and other modifications. |
| 206 | +# |
| 207 | +# Using the OOP approach allows for `fig` and `ax` to use separate methods to |
| 208 | +# manipulate the visualization. Instead of using the module `pyplot` for each |
| 209 | +# instance of managing the objects, the specfic axes refers to OOP usage and |
| 210 | +# manages data |
| 211 | +# |
| 212 | +# .. note:: |
196 | 213 | #
|
| 214 | +# The names and spelling for methods may be similar for both `pyplot` and OOP |
| 215 | +# approaches. Errors may occur when using the wrong corresponding method. |
| 216 | +# Confirm with documentation API for specific method names. |
| 217 | + |
| 218 | +############################################################################## |
197 | 219 | #
|
| 220 | +# Customizations |
| 221 | +# ============== |
198 | 222 | #
|
| 223 | +# There are four main parts to building a visualization with Matplotlib, the |
| 224 | +# figure, the axes, the axis, and the artist(s). |
199 | 225 | #
|
| 226 | +# Components of Matplotlib Figure |
| 227 | +# ------------------------------- |
200 | 228 | #
|
| 229 | +# This |
0 commit comments