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

Skip to content

Commit 5b5b3c9

Browse files
committed
Hopefully improving the wording in usage_faq.rst to make clear the differences between pyplot and pylab.
1 parent 1ea3e1f commit 5b5b3c9

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

doc/faq/usage_faq.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,47 @@ module in matplotlib.
1919

2020
Pyplot provides a MATLAB-style state-machine interface to
2121
the underlying object-oriented plotting library in matplotlib.
22+
For example, calling a plotting function from pyplot will
23+
automatically create the necessary figure and axes to achieve
24+
the desired plot. Setting a title through pyplot will automatically
25+
set the title to the current axes object.
2226

2327
Pylab combines the pyplot functionality (for plotting) with the numpy
2428
functionality (for mathematics and for working with arrays)
2529
in a single namespace, making that namespace
26-
(or environment) even more MATLAB-like. This is what you get if
27-
you use the
30+
(or environment) even more MATLAB-like.
31+
For example, one can call the `sin` and `cos` functions just like
32+
you could in MATLAB, as well as having all the features of pyplot.
33+
34+
The pyplot interface is generally preferred for non-interactive plotting
35+
(i.e., scripting). The pylab interface is generally preferred for interactive
36+
plotting in the python shell. Note that this is what you get if you use the
2837
*ipython* shell with the *-pylab* option, which imports everything
2938
from pylab and makes plotting fully interactive.
3039

3140
We have been gradually converting the matplotlib examples
32-
from pure MATLAB-style, using "from pylab import \*", to a preferred
41+
from pure MATLAB-style (using "from pylab import \*"), to a preferred
3342
style in which pyplot is used for some convenience functions, either
3443
pyplot or the object-oriented style is used for the remainder of the
3544
plotting code, and numpy is used explicitly for numeric array operations.
3645

37-
In this preferred style, the imports at the top are::
46+
In this preferred style, the imports at the top of your script are::
3847

3948
import matplotlib.pyplot as plt
4049
import numpy as np
4150

4251
Then one calls, for example, np.arange, np.zeros, np.pi, plt.figure,
4352
plt.plot, plt.show, etc.
4453

45-
Example, pure MATLAB-style::
54+
Example in pure MATLAB-style::
4655

4756
from pylab import *
4857
x = arange(0, 10, 0.2)
4958
y = sin(x)
5059
plot(x, y)
5160
show()
5261

53-
Now in preferred style, but still using pyplot interface::
62+
Now in preferred style, using the pyplot interface::
5463

5564
import matplotlib.pyplot as plt
5665
import numpy as np
@@ -59,7 +68,8 @@ Now in preferred style, but still using pyplot interface::
5968
plt.plot(x, y)
6069
plt.show()
6170

62-
And using pyplot convenience functions, but object-orientation for the rest::
71+
For full control of your plots and more advanced usage, use the pyplot
72+
interface for creating figures, but then use object-orientation for the rest::
6373

6474
import matplotlib.pyplot as plt
6575
import numpy as np
@@ -70,7 +80,7 @@ And using pyplot convenience functions, but object-orientation for the rest::
7080
ax.plot(x, y)
7181
plt.show()
7282

73-
So, why do all the extra typing required as one moves away from the pure
83+
So, why all the extra typing required as one moves away from the pure
7484
MATLAB-style? For very simple things like this example, the only
7585
advantage is educational: the wordier styles are more explicit, more
7686
clear as to where things come from and what is going on. For more

0 commit comments

Comments
 (0)