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

Skip to content

Commit 71dc35a

Browse files
tacaswellpelson
authored andcommitted
DOC : edits to usage_faq.rst
1 parent fbe82f2 commit 71dc35a

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

doc/faq/usage_faq.rst

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,47 +48,48 @@ completely, leaving a purely object-oriented approach.
4848

4949
.. _pylab:
5050

51-
Matplotlib, pylab, and pyplot: how are they related?
51+
Matplotlib, pyplot and pylab: how are they related?
5252
====================================================
5353

54-
Matplotlib is the whole package; :mod:`pylab` is a module in matplotlib
55-
that gets installed alongside :mod:`matplotlib`; and :mod:`matplotlib.pyplot`
56-
is a module in matplotlib.
54+
Matplotlib is the whole package; :mod:`matplotlib.pyplot`
55+
is a module in matplotlib; and :mod:`pylab` is a module
56+
that gets installed alongside :mod:`matplotlib`.
5757

58-
Pyplot provides the state-machine interface to the underlying OO plotting
59-
library in matplotlib. This means that figures and axes are implicitly
60-
and automatically created to achieve the desired plot. For example,
61-
calling ``plot`` from pyplot will automatically create the necessary
62-
figure and axes to achieve the desired plot. Setting a title will
63-
then automatically set that title to the current axes object::
58+
Pyplot provides the state-machine interface to the underlying
59+
object-oriented plotting library. The state-machine implicitly and
60+
automatically creates figures and axes to achieve the desired
61+
plot. For example::
6462

6563

66-
.. sourcecode:: ipython
64+
import matplotlib.pyplot as plt
65+
import numpy as np
6766

68-
In [14]: %matplotlib
69-
Using matplotlib backend: Qt4Agg
67+
x = np.linspace(0, 2, 100)
7068

71-
In [15]: import matplotlib.pyplot as plt
69+
plt.plot(x, x, label='linear')
70+
plt.plot(x, x**2, label='quadratic')
71+
plt.plot(x, x**3, label='cubic')
7272

73-
In [16]: plt.plot(range(10), range(10))
74-
Out[16]: [<matplotlib.lines.Line2D at 0x7fdfef9be1d0>]
73+
plt.xlabel('x label')
74+
plt.ylabel('y label')
7575

76-
In [17]: plt.title("Simple Plot")
77-
Out[17]: <matplotlib.text.Text at 0x7fdfee53d0d0>
76+
plt.title("Simple Plot")
7877

79-
This is very convenient for interactive use, however
80-
because the commands have side-effects (altering the global state)
81-
using many :mod:`matplotlib.pyplot` commands in scripts or functions
82-
can lead to unexpected and difficult to track down bugs.
78+
plt.legend()
8379

84-
Pylab is a convenience module that imports pyplot (for plotting) and
85-
numpy functionality (for mathematics and for working with arrays) in a
86-
single namespace. You can than bulk import from pylab to get an even
87-
more MATLAB-like environment. This seems convenient for interactive
88-
calculations and plotting, as it (barely) minimizes typing, however it
89-
is not recommended as it clobbers your namespace. As with :mod:`pyplot`,
90-
it is not recommended to use :mod:`pylab` in scripts and bulk importing
91-
:mod:`pylab` in scripts is discouraged as with all bulk importing.
80+
plt.show()
81+
82+
The first call to ``plt.plot`` will automatically create the necessary
83+
figure and axes to achieve the desired plot. Subsequent calls to
84+
``plt.plot`` re-use the current axes and each add another line.
85+
Setting the title, legend, and axis labels also automatically use the
86+
current axes and set the title, create the legend, and label the axis
87+
respectively.
88+
89+
:mod:`pylab` is a convenience module that bulk imports
90+
:mod:`matplotlib.pyplot` (for plotting) and :mod:`numpy`
91+
(for mathematics and working with arrays) in a single name space.
92+
Although many examples use :mod:`pylab`, it is no longer recommended.
9293

9394
For non-interactive plotting it is suggested
9495
to use pyplot to create the figures and then the OO interface for
@@ -112,7 +113,7 @@ The only caveat is to avoid mixing the coding styles for your own code.
112113
Of the different styles, there are two that are officially supported.
113114
Therefore, these are the preferred ways to use matplotlib.
114115

115-
For the preferred pyplot style, the imports at the top of your
116+
For the pyplot style, the imports at the top of your
116117
scripts will typically be::
117118

118119
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)