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

Skip to content

Commit 2ccbdea

Browse files
committed
Added more explanation of pyplot/OOP
1 parent 494b1aa commit 2ccbdea

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

tutorials/introductory/getting_started.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#
2323
# There are two main ways of producing plots with Matplotlib, stateful and
2424
# 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.
2727
#
2828
# The stateful `pyplot` approach to generate plots is simple. It is helpful
2929
# for basic plots and for interactive environments, such as Jupyter Notebooks.
@@ -119,12 +119,12 @@
119119
# data structures.
120120
#
121121

122-
"""Sample Data"""
122+
# Sample Data
123123

124124
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
125125
'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]
128128
chk_acct_09 = [1250, 1325, 1200, 1220, 1100, 1055,
129129
1255, 1090, 1190, 1205, 1205, 1180]
130130
svg_acct_09 = [1000, 1050, 1100, 1150, 1200, 1250,
@@ -138,7 +138,7 @@
138138
#
139139
# .. note::
140140
#
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.
142142
#
143143
# Stateful: `pyplot`
144144
# ------------------
@@ -149,7 +149,7 @@
149149
# Additional parts of the figure are also available through the module
150150
# methods.
151151

152-
"""Stateful programming with pyplot"""
152+
# Stateful programming with pyplot
153153

154154
x = months
155155
y1 = income
@@ -166,15 +166,22 @@
166166

167167
##############################################################################
168168
#
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+
#
169175
# Stateless: Object Oriented Programming (OOP)
170176
# --------------------------------------------
171177
#
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.
176183

177-
"""Stateless programming with OOP"""
184+
# Stateless programming with OOP
178185

179186
y4 = chk_acct_10
180187
y5 = svg_acct_10
@@ -191,10 +198,32 @@
191198

192199
##############################################################################
193200
#
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::
196213
#
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+
##############################################################################
197219
#
220+
# Customizations
221+
# ==============
198222
#
223+
# There are four main parts to building a visualization with Matplotlib, the
224+
# figure, the axes, the axis, and the artist(s).
199225
#
226+
# Components of Matplotlib Figure
227+
# -------------------------------
200228
#
229+
# This

0 commit comments

Comments
 (0)