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

Skip to content

Commit 9abbf92

Browse files
committed
Switch explicit/implicit order and text.
1 parent 3933158 commit 9abbf92

File tree

1 file changed

+101
-96
lines changed

1 file changed

+101
-96
lines changed

tutorials/introductory/getting_started.py

Lines changed: 101 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818
# The library is accessible through a variety of operating systems and
1919
# programming environments. The fundamental ideas behind Matplotlib for
2020
# visualizations involve taking data and transforming it through functions and
21-
# methods.
22-
#
23-
# There are two main ways of producing graphs with Matplotlib, stateful and
24-
# stateless. Stateful code, using `pyplot`, or stateless code, using Object
25-
# Oriented Programming (OOP), are the foundation for creating and manipulating
26-
# data into visualizations.
21+
# methods. This process occurs on the backend and is not user-facing. For more
22+
# information regarding manipulating backend capabilities, see """ref""".
2723
#
28-
# The stateful `pyplot` approach to generate plots is simple. It is helpful
29-
# for basic plots and for interactive environments, such as Jupyter Notebooks.
30-
# Users familiar with MATLAB or would like to have Matplotlib automatically
31-
# create and manage parts of the visualization benefit from using `pyplot`
32-
# functions to plot their data.
24+
# There are two main ways of producing graphs with Matplotlib, explicit and
25+
# implicit. Explicit code, using Object Oriented Programmiong (OOP), and
26+
# implicit code, using `pyplot`, are the foundation for creating and
27+
# manipulating data into visualizations.
3328
#
34-
# Stateless programming, OOP, helps users generalize code and is useful for
29+
# Explicit programming, OOP, helps users generalize code and is useful for
3530
# repeated uses or larger projects. This is also a more robust way of
3631
# controlling customizations for visualizations. Users looking to have control
3732
# over every part of the graph can call methods on each item.
3833
#
34+
# The implicit `pyplot` approach to generate plots is simple. It is helpful
35+
# for basic plots and for interactive environments, such as Jupyter Notebooks.
36+
# Users familiar with MATLAB or would like to have Matplotlib automatically
37+
# create and manage parts of the visualization benefit from using `pyplot`
38+
# functions to plot their data.
3939
#
4040
#
4141

@@ -71,6 +71,11 @@
7171
#
7272
# `python -m pip install matplotlib`
7373
#
74+
# .. note::
75+
#
76+
# If you would like to contribute to Matplotlib, see the developer
77+
# installation guide for details about the process.
78+
#
7479
# Interactive environments
7580
# ------------------------
7681
#
@@ -84,8 +89,8 @@
8489
# ========
8590
#
8691
# The common conventions for preparing to plot data involve importing the
87-
# necessary libraries with abbreviations for convenience. Both stateful and
88-
# stateless programming require the following.
92+
# necessary libraries with abbreviations for convenience. Both implicit and
93+
# explicit programming require the following.
8994

9095
import matplotlib.pyplot as plt
9196

@@ -97,24 +102,25 @@
97102
#
98103
# These are the two common strategies for creating plots with Matplotlib.
99104
#
100-
# * Stateful: The programming is designed to remember preceding events or
101-
# interactions. Matplotlib automatically manages figures and axes.
102-
# * `pyplot`, most similar to MATLAB and convenient for interactive
103-
# environments.
104-
# * Stateless: Code has explicit references to objects. Users manage objects
105+
# * Explicit: Code has explicit references to objects. Users manage objects
105106
# for specific figures and axes and call on methods for manipulating data.
106107
# * Object-oriented programming (OOP), robust control and useful for
107108
# generalized code.
108109
#
110+
# * Implicit: The programming is designed to remember preceding events or
111+
# interactions. Matplotlib automatically manages figures and axes.
112+
# * `pyplot`, most similar to MATLAB and convenient for interactive
113+
# environments.
114+
#
109115
# .. note::
110116
#
111-
# The Matplotlib community does not recommend interchanging stateful and
112-
# stateless strategies. When using one as standard, all code should follow
113-
# the same strategy. Switching back and forth between stateful and
114-
# stateless programming can yield errors.
117+
# The Matplotlib community does not recommend interchanging explicit and
118+
# implicit strategies. When using one as standard, all code should follow
119+
# the same strategy. Switching back and forth between explicit and
120+
# implicit programming can yield errors.
115121
#
116122
# For other techniques of creating plots with Matplotlib, refer to
117-
# """insert reference""".
123+
# """ref""".
118124
#
119125
# Data
120126
# ----
@@ -147,57 +153,27 @@
147153
# Other containers, such as `pandas` data objects, may not work as
148154
# intended.
149155
#
150-
# Stateful: `pyplot`
151-
# ------------------
152-
#
153-
# To use stateful programming for Matplotlib involves using the `pyplot`
154-
# module. The figure and axes are automatically generated by the module.
155-
# Pass data through as arguments using methods within the module.
156-
# Additional parts of the figure are also available through the module
157-
# methods.
158-
159-
# Stateful programming with pyplot
160-
161-
x = months
162-
y1 = income
163-
y2 = chk_acct_09
164-
y3 = svg_acct_09
165-
166-
plt.plot(x, y1, label='Income')
167-
plt.plot(x, y2, label='Checking Account')
168-
plt.plot(x, y3, label='Savings Account')
169-
plt.xlabel('Month') # Module methods generate parts of figure.
170-
plt.ylabel('USD')
171-
plt.title("Personal Financial Tracking from 2009")
172-
plt.legend()
173-
174-
##############################################################################
175-
#
176-
# In the example above, the `pyplot` module contains its own methods of
177-
# actionable tasks for the data. The `plt.plot` plots data as a line graph
178-
# with various keyword arguments as customizable options. The module also
179-
# includes other methods for generating parts of the visualization. These parts
180-
# use different methods from the OOP approach.
181-
#
182-
# Stateless: Object Oriented Programming (OOP)
156+
# Explicit: Object Oriented Programming (OOP)
183157
# --------------------------------------------
184158
#
185-
# To use stateless programming for Matplotlib involves using a single instance
159+
# To use explicit programming for Matplotlib involves using a single instance
186160
# of the `pyplot` module to unpack a set or sets of explicit figure and axes.
187161
# Each axes has its own methods to graph data. In addition, each axes also
188162
# uses separate methods to create and manage parts of a figure. These methods
189-
# are different from those of the stateful programming approach.
163+
# are different from those of the implicit programming approach.
190164

191-
# Stateless programming with OOP
165+
# Explicit programming with OOP
192166

193-
y4 = chk_acct_10
194-
y5 = svg_acct_10
167+
x = months
168+
y1 = income
169+
y2 = chk_acct_09
170+
y3 = svg_acct_09
195171

196172
fig, ax = plt.subplots() # Figure & axes unpacked separately with module.
197173

198174
ax.plot(x, y1, label='Checking Account')
199-
ax.plot(x, y4, label='Savings Account')
200-
ax.plot(x, y5, label='Income')
175+
ax.plot(x, y2, label='Savings Account')
176+
ax.plot(x, y3, label='Income')
201177
ax.set_xlabel('Month') # Axes use separate methods to manage parts of figure.
202178
ax.set_ylabel('USD')
203179
ax.set_title('Personal Financial Tracking from 2010')
@@ -216,6 +192,36 @@
216192
# instances of managing objects, the specfic axes refers to OOP usage and
217193
# manages the respective data.
218194
#
195+
# Implicit: `pyplot`
196+
# ------------------
197+
#
198+
# To use implicit programming for Matplotlib involves using the `pyplot`
199+
# module. The figure and axes are automatically generated by the module.
200+
# Pass data through as arguments using methods within the module.
201+
# Additional parts of the figure are also available through the module
202+
# methods.
203+
204+
# Implicit programming with pyplot
205+
206+
y4 = chk_acct_10
207+
y5 = svg_acct_10
208+
209+
plt.plot(x, y1, label='Income')
210+
plt.plot(x, y4, label='Checking Account')
211+
plt.plot(x, y5, label='Savings Account')
212+
plt.xlabel('Month') # Module methods generate parts of figure.
213+
plt.ylabel('USD')
214+
plt.title("Personal Financial Tracking from 2009")
215+
plt.legend()
216+
217+
##############################################################################
218+
#
219+
# In the example above, the `pyplot` module contains its own methods of
220+
# actionable tasks for the data. The `plt.plot` plots data as a line graph
221+
# with various keyword arguments as customizable options. The module also
222+
# includes other methods for generating parts of the visualization. These parts
223+
# use different methods from the OOP approach.
224+
#
219225
# .. note::
220226
#
221227
# The names and spelling for methods may be similar for both `pyplot` and
@@ -243,12 +249,12 @@
243249
# * Axes are subplots within the figure. They contain figure elements and
244250
# are responsible for plotting and configuring additional details.
245251
# * Note: Axes and Axis are not synonymous. Axis refers to
246-
# """insert reference""".
252+
# """ref""".
247253
#
248254
# Multiple Graphs within a Figure
249255
# -------------------------------
250256
#
251-
# For multiple graphs using a single figure, stateful and stateless approaches
257+
# For multiple graphs using a single figure, explicit and implicit approaches
252258
# use a similar convention for mapping out multiple axes. Matplotlib manages
253259
# more than one axes in a two-dimensional matrix. They are arranged by row
254260
# amount and then by column amount. The third argument represents the specific
@@ -257,39 +263,12 @@
257263
# When looking for more complex solutions to multiple graphs within a figure,
258264
# use the GridSpec module to organize the layout.
259265

260-
# Stateful with pyplot
261-
262-
plt.subplot(1, 2, 1)
263-
plt.plot(x, y1, label='Income')
264-
plt.plot(x, y2, label='Checking')
265-
plt.plot(x, y1, color='green', label='Savings')
266-
plt.xticks(x, months, rotation=270)
267-
plt.title('2009', fontsize='small')
268-
269-
plt.subplot(1, 2, 2)
270-
plt.plot(x, y1, label='Income')
271-
plt.plot(x, y4, label='Checking')
272-
plt.plot(x, y5, color='green', label='Savings')
273-
plt.xticks(x, months, rotation=270)
274-
plt.title('2009', fontsize='small')
275-
plt.legend(bbox_to_anchor=(1, 1), loc='upper left')
276-
277-
plt.suptitle('Personal Financial Tracking', weight='black')
278-
plt.tight_layout()
266+
# Explicit with OOP
279267

280-
##############################################################################
281-
#
282-
# The `pyplot` example above uses two axes to graph data. In each instance,
283-
# Matplotlib auotmatically manages the specific axes so that each action of
284-
# plotting data does not interfere with the previous instance.
285-
286-
# Stateless with OOP
287-
288-
fig, (ax1, ax2) = plt.subplots(2, 1, sharey='row',
268+
fig, (ax1, ax2) = plt.subplots(1, 2, sharey='row',
289269
figsize=[8, 4], constrained_layout=True)
290-
# Note the different method name for OOP.
291270

292-
fig.suptitle('Personal Financial Tarcking \'09 - \'10',
271+
fig.suptitle('Personal Financial Tracking \'09 - \'10',
293272
fontsize=16, weight='black')
294273

295274
ax1.plot(x, y1, label='Income')
@@ -310,3 +289,29 @@
310289
# The OOP example above also uses two axes to graph the data. However, the OOP
311290
# approach must refer to an explicitly generated axes after creating both the
312291
# figure and axes.
292+
293+
# Implicit with pyplot
294+
295+
plt.subplot(1, 2, 1) # Note the different method name for implicit.
296+
plt.plot(x, y1, label='Income')
297+
plt.plot(x, y2, label='Checking')
298+
plt.plot(x, y1, color='green', label='Savings')
299+
plt.xticks(x, months, rotation=270)
300+
plt.title('2009', fontsize='small')
301+
302+
plt.subplot(1, 2, 2)
303+
plt.plot(x, y1, label='Income')
304+
plt.plot(x, y4, label='Checking')
305+
plt.plot(x, y5, color='green', label='Savings')
306+
plt.xticks(x, months, rotation=270)
307+
plt.title('2009', fontsize='small')
308+
plt.legend(bbox_to_anchor=(1, 1), loc='upper left')
309+
310+
plt.suptitle('Personal Financial Tracking', weight='black')
311+
plt.tight_layout()
312+
313+
##############################################################################
314+
#
315+
# The `pyplot` example above uses two axes to graph data. In each instance,
316+
# Matplotlib auotmatically manages the specific axes so that each action of
317+
# plotting data does not interfere with the previous instance.

0 commit comments

Comments
 (0)