5
5
:suppress:
6
6
7
7
import numpy as np
8
+ from numpy.random import randn, rand, randint
8
9
np.random.seed(123456 )
9
- from pandas import *
10
+ from pandas import DataFrame, Series, date_range, options
10
11
import pandas.util.testing as tm
11
- randn = np.random.randn
12
12
np.set_printoptions(precision = 4 , suppress = True )
13
13
import matplotlib.pyplot as plt
14
14
plt.close(' all' )
15
- options.display.mpl_style= ' default'
15
+ options.display.mpl_style = ' default'
16
16
17
17
************************
18
18
Plotting with matplotlib
@@ -60,8 +60,7 @@ On DataFrame, ``plot`` is a convenience to plot all of the columns with labels:
60
60
61
61
.. ipython :: python
62
62
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' ))
65
64
df = df.cumsum()
66
65
67
66
@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
101
100
102
101
plt.figure()
103
102
104
- df3 = DataFrame(np.random. randn(1000 , 2 ), columns = [' B' , ' C' ]).cumsum()
103
+ df3 = DataFrame(randn(1000 , 2 ), columns = [' B' , ' C' ]).cumsum()
105
104
df3[' A' ] = Series(range (len (df)))
106
105
107
106
@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:
169
168
df.A.plot()
170
169
171
170
172
- Using the ``x_compat `` parameter, you can suppress this bevahior :
171
+ Using the ``x_compat `` parameter, you can suppress this behavior :
173
172
174
173
.. ipython :: python
175
174
@@ -200,6 +199,15 @@ Targeting different subplots
200
199
201
200
You can pass an ``ax `` argument to ``Series.plot `` to plot on a particular axis:
202
201
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
+
203
211
.. ipython :: python
204
212
205
213
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:
210
218
@savefig series_plot_multi.png width =6in
211
219
df[' D' ].plot(ax = axes[1 ,1 ]); axes[1 ,1 ].set_title(' D' )
212
220
221
+
213
222
.. _visualization.other :
214
223
215
224
Other plotting features
@@ -239,7 +248,7 @@ bar plot:
239
248
240
249
.. ipython :: python
241
250
242
- df2 = DataFrame(np.random. rand(10 , 4 ), columns = [' a' , ' b' , ' c' , ' d' ])
251
+ df2 = DataFrame(rand(10 , 4 ), columns = [' a' , ' b' , ' c' , ' d' ])
243
252
244
253
@savefig bar_plot_multi_ex.png width =5in
245
254
df2.plot(kind = ' bar' );
@@ -298,10 +307,10 @@ New since 0.10.0, the ``by`` keyword can be specified to plot grouped histograms
298
307
299
308
.. ipython :: python
300
309
301
- data = Series(np.random. randn(1000 ))
310
+ data = Series(randn(1000 ))
302
311
303
312
@savefig grouped_hist.png width =6in
304
- data.hist(by = np.random. randint(0 , 4 , 1000 ))
313
+ data.hist(by = randint(0 , 4 , 1000 ))
305
314
306
315
307
316
.. _visualization.box :
@@ -317,7 +326,7 @@ a uniform random variable on [0,1).
317
326
318
327
.. ipython :: python
319
328
320
- df = DataFrame(np.random. rand(10 ,5 ))
329
+ df = DataFrame(rand(10 ,5 ))
321
330
plt.figure();
322
331
323
332
@savefig box_plot_ex.png width =6in
@@ -328,7 +337,7 @@ groupings. For instance,
328
337
329
338
.. ipython :: python
330
339
331
- df = DataFrame(np.random. rand(10 ,2 ), columns = [' Col1' , ' Col2' ] )
340
+ df = DataFrame(rand(10 ,2 ), columns = [' Col1' , ' Col2' ] )
332
341
df[' X' ] = Series([' A' ,' A' ,' A' ,' A' ,' A' ,' B' ,' B' ,' B' ,' B' ,' B' ])
333
342
334
343
plt.figure();
@@ -341,7 +350,7 @@ columns:
341
350
342
351
.. ipython :: python
343
352
344
- df = DataFrame(np.random. rand(10 ,3 ), columns = [' Col1' , ' Col2' , ' Col3' ])
353
+ df = DataFrame(rand(10 ,3 ), columns = [' Col1' , ' Col2' , ' Col3' ])
345
354
df[' X' ] = Series([' A' ,' A' ,' A' ,' A' ,' A' ,' B' ,' B' ,' B' ,' B' ,' B' ])
346
355
df[' Y' ] = Series([' A' ,' B' ,' A' ,' B' ,' A' ,' B' ,' A' ,' B' ,' A' ,' B' ])
347
356
@@ -361,7 +370,7 @@ Scatter plot matrix
361
370
.. ipython :: python
362
371
363
372
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' ])
365
374
366
375
@savefig scatter_matrix_kde.png width =6in
367
376
scatter_matrix(df, alpha = 0.2 , figsize = (6 , 6 ), diagonal = ' kde' )
@@ -378,7 +387,7 @@ setting `kind='kde'`:
378
387
379
388
.. ipython :: python
380
389
381
- ser = Series(np.random. randn(1000 ))
390
+ ser = Series(randn(1000 ))
382
391
383
392
@savefig kde_plot.png width =6in
384
393
ser.plot(kind = ' kde' )
@@ -444,7 +453,7 @@ implies that the underlying data are not random.
444
453
445
454
plt.figure()
446
455
447
- data = Series(0.1 * np.random.random (1000 ) +
456
+ data = Series(0.1 * rand (1000 ) +
448
457
0.9 * np.sin(np.linspace(- 99 * np.pi, 99 * np.pi, num = 1000 )))
449
458
450
459
@savefig lag_plot.png width =6in
@@ -467,7 +476,7 @@ confidence band.
467
476
468
477
plt.figure()
469
478
470
- data = Series(0.7 * np.random.random (1000 ) +
479
+ data = Series(0.7 * rand (1000 ) +
471
480
0.3 * np.sin(np.linspace(- 9 * np.pi, 9 * np.pi, num = 1000 )))
472
481
473
482
@savefig autocorrelation_plot.png width =6in
@@ -488,7 +497,7 @@ are what constitutes the bootstrap plot.
488
497
489
498
from pandas.tools.plotting import bootstrap_plot
490
499
491
- data = Series(np.random.random (1000 ))
500
+ data = Series(rand (1000 ))
492
501
493
502
@savefig bootstrap_plot.png width =6in
494
503
bootstrap_plot(data, size = 50 , samples = 500 , color = ' grey' )
0 commit comments