Skip to content

Commit 359c736

Browse files
committed
DOC/BUG: fix overwriting of 'df' variable in doc build
1 parent 9403b11 commit 359c736

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

doc/source/visualization.rst

+27-18
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
:suppress:
66
77
import numpy as np
8+
from numpy.random import randn, rand, randint
89
np.random.seed(123456)
9-
from pandas import *
10+
from pandas import DataFrame, Series, date_range, options
1011
import pandas.util.testing as tm
11-
randn = np.random.randn
1212
np.set_printoptions(precision=4, suppress=True)
1313
import matplotlib.pyplot as plt
1414
plt.close('all')
15-
options.display.mpl_style='default'
15+
options.display.mpl_style = 'default'
1616
1717
************************
1818
Plotting with matplotlib
@@ -60,8 +60,7 @@ On DataFrame, ``plot`` is a convenience to plot all of the columns with labels:
6060

6161
.. ipython:: python
6262
63-
df = DataFrame(randn(1000, 4), index=ts.index,
64-
columns=['A', 'B', 'C', 'D'])
63+
df = DataFrame(randn(1000, 4), index=ts.index, columns=list('ABCD'))
6564
df = df.cumsum()
6665
6766
@savefig frame_plot_basic.png width=6in
@@ -101,7 +100,7 @@ You can plot one column versus another using the `x` and `y` keywords in
101100
102101
plt.figure()
103102
104-
df3 = DataFrame(np.random.randn(1000, 2), columns=['B', 'C']).cumsum()
103+
df3 = DataFrame(randn(1000, 2), columns=['B', 'C']).cumsum()
105104
df3['A'] = Series(range(len(df)))
106105
107106
@savefig df_plot_xy.png width=6in
@@ -169,7 +168,7 @@ Here is the default behavior, notice how the x-axis tick labelling is performed:
169168
df.A.plot()
170169
171170
172-
Using the ``x_compat`` parameter, you can suppress this bevahior:
171+
Using the ``x_compat`` parameter, you can suppress this behavior:
173172

174173
.. ipython:: python
175174
@@ -200,6 +199,15 @@ Targeting different subplots
200199

201200
You can pass an ``ax`` argument to ``Series.plot`` to plot on a particular axis:
202201

202+
.. ipython:: python
203+
:suppress:
204+
205+
ts = Series(randn(1000), index=date_range('1/1/2000', periods=1000))
206+
ts = ts.cumsum()
207+
208+
df = DataFrame(randn(1000, 4), index=ts.index, columns=list('ABCD'))
209+
df = df.cumsum()
210+
203211
.. ipython:: python
204212
205213
fig, axes = plt.subplots(nrows=2, ncols=2)
@@ -210,6 +218,7 @@ You can pass an ``ax`` argument to ``Series.plot`` to plot on a particular axis:
210218
@savefig series_plot_multi.png width=6in
211219
df['D'].plot(ax=axes[1,1]); axes[1,1].set_title('D')
212220
221+
213222
.. _visualization.other:
214223

215224
Other plotting features
@@ -239,7 +248,7 @@ bar plot:
239248
240249
.. ipython:: python
241250
242-
df2 = DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
251+
df2 = DataFrame(rand(10, 4), columns=['a', 'b', 'c', 'd'])
243252
244253
@savefig bar_plot_multi_ex.png width=5in
245254
df2.plot(kind='bar');
@@ -298,10 +307,10 @@ New since 0.10.0, the ``by`` keyword can be specified to plot grouped histograms
298307
299308
.. ipython:: python
300309
301-
data = Series(np.random.randn(1000))
310+
data = Series(randn(1000))
302311
303312
@savefig grouped_hist.png width=6in
304-
data.hist(by=np.random.randint(0, 4, 1000))
313+
data.hist(by=randint(0, 4, 1000))
305314
306315
307316
.. _visualization.box:
@@ -317,7 +326,7 @@ a uniform random variable on [0,1).
317326

318327
.. ipython:: python
319328
320-
df = DataFrame(np.random.rand(10,5))
329+
df = DataFrame(rand(10,5))
321330
plt.figure();
322331
323332
@savefig box_plot_ex.png width=6in
@@ -328,7 +337,7 @@ groupings. For instance,
328337

329338
.. ipython:: python
330339
331-
df = DataFrame(np.random.rand(10,2), columns=['Col1', 'Col2'] )
340+
df = DataFrame(rand(10,2), columns=['Col1', 'Col2'] )
332341
df['X'] = Series(['A','A','A','A','A','B','B','B','B','B'])
333342
334343
plt.figure();
@@ -341,7 +350,7 @@ columns:
341350

342351
.. ipython:: python
343352
344-
df = DataFrame(np.random.rand(10,3), columns=['Col1', 'Col2', 'Col3'])
353+
df = DataFrame(rand(10,3), columns=['Col1', 'Col2', 'Col3'])
345354
df['X'] = Series(['A','A','A','A','A','B','B','B','B','B'])
346355
df['Y'] = Series(['A','B','A','B','A','B','A','B','A','B'])
347356
@@ -361,7 +370,7 @@ Scatter plot matrix
361370
.. ipython:: python
362371
363372
from pandas.tools.plotting import scatter_matrix
364-
df = DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])
373+
df = DataFrame(randn(1000, 4), columns=['a', 'b', 'c', 'd'])
365374
366375
@savefig scatter_matrix_kde.png width=6in
367376
scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')
@@ -378,7 +387,7 @@ setting `kind='kde'`:
378387
379388
.. ipython:: python
380389
381-
ser = Series(np.random.randn(1000))
390+
ser = Series(randn(1000))
382391
383392
@savefig kde_plot.png width=6in
384393
ser.plot(kind='kde')
@@ -444,7 +453,7 @@ implies that the underlying data are not random.
444453
445454
plt.figure()
446455
447-
data = Series(0.1 * np.random.random(1000) +
456+
data = Series(0.1 * rand(1000) +
448457
0.9 * np.sin(np.linspace(-99 * np.pi, 99 * np.pi, num=1000)))
449458
450459
@savefig lag_plot.png width=6in
@@ -467,7 +476,7 @@ confidence band.
467476
468477
plt.figure()
469478
470-
data = Series(0.7 * np.random.random(1000) +
479+
data = Series(0.7 * rand(1000) +
471480
0.3 * np.sin(np.linspace(-9 * np.pi, 9 * np.pi, num=1000)))
472481
473482
@savefig autocorrelation_plot.png width=6in
@@ -488,7 +497,7 @@ are what constitutes the bootstrap plot.
488497
489498
from pandas.tools.plotting import bootstrap_plot
490499
491-
data = Series(np.random.random(1000))
500+
data = Series(rand(1000))
492501
493502
@savefig bootstrap_plot.png width=6in
494503
bootstrap_plot(data, size=50, samples=500, color='grey')

0 commit comments

Comments
 (0)