@@ -135,7 +135,16 @@ These include:
135
135
* :ref: `'hexbin' <visualization.hexbin >` for hexagonal bin plots
136
136
* :ref: `'pie' <visualization.pie >` for pie plots
137
137
138
- .. versionadded :: 0.17
138
+ For example, a bar plot can be created the following way:
139
+
140
+ .. ipython :: python
141
+
142
+ plt.figure();
143
+
144
+ @savefig bar_plot_ex.png
145
+ df.ix[5 ].plot(kind = ' bar' ); plt.axhline(0 , color = ' k' )
146
+
147
+ .. versionadded :: 0.17.0
139
148
140
149
You can also create these other plots using the methods ``DataFrame.plot.<kind> `` instead of providing the ``kind `` keyword argument. This makes it easier to discover plot methods and the specific arguments they use:
141
150
@@ -178,9 +187,9 @@ For labeled, non-time series data, you may wish to produce a bar plot:
178
187
plt.figure();
179
188
180
189
@savefig bar_plot_ex.png
181
- df.ix[5 ].plot( kind = ' bar' ); plt.axhline(0 , color = ' k' )
190
+ df.ix[5 ].plot. bar( ); plt.axhline(0 , color = ' k' )
182
191
183
- Calling a DataFrame's :meth: `~DataFrame.plot ` method with `` kind='bar' `` produces a multiple
192
+ Calling a DataFrame's :meth: `~DataFrame.plot.bar ` method produces a multiple
184
193
bar plot:
185
194
186
195
.. ipython :: python
@@ -195,7 +204,7 @@ bar plot:
195
204
df2 = pd.DataFrame(np.random.rand(10 , 4 ), columns = [' a' , ' b' , ' c' , ' d' ])
196
205
197
206
@savefig bar_plot_multi_ex.png
198
- df2.plot( kind = ' bar' );
207
+ df2.plot. bar( );
199
208
200
209
To produce a stacked bar plot, pass ``stacked=True ``:
201
210
@@ -208,9 +217,9 @@ To produce a stacked bar plot, pass ``stacked=True``:
208
217
.. ipython :: python
209
218
210
219
@savefig bar_plot_stacked_ex.png
211
- df2.plot( kind = ' bar' , stacked = True );
220
+ df2.plot. bar( stacked = True );
212
221
213
- To get horizontal bar plots, pass `` kind=' barh' `` :
222
+ To get horizontal bar plots, use the `` barh `` method :
214
223
215
224
.. ipython :: python
216
225
:suppress:
@@ -221,7 +230,7 @@ To get horizontal bar plots, pass ``kind='barh'``:
221
230
.. ipython :: python
222
231
223
232
@savefig barh_plot_stacked_ex.png
224
- df2.plot( kind = ' barh' , stacked = True );
233
+ df2.plot. barh( stacked = True );
225
234
226
235
.. _visualization.hist :
227
236
@@ -230,7 +239,7 @@ Histograms
230
239
231
240
.. versionadded :: 0.15.0
232
241
233
- Histogram can be drawn specifying `` kind=' hist' `` .
242
+ Histogram can be drawn by using the :meth: ` DataFrame.plot. hist` and :meth: ` Series.plot.hist ` methods .
234
243
235
244
.. ipython :: python
236
245
@@ -240,7 +249,7 @@ Histogram can be drawn specifying ``kind='hist'``.
240
249
plt.figure();
241
250
242
251
@savefig hist_new.png
243
- df4.plot( kind = ' hist' , alpha = 0.5 )
252
+ df4.plot. hist( alpha = 0.5 )
244
253
245
254
246
255
.. ipython :: python
@@ -255,7 +264,7 @@ Histogram can be stacked by ``stacked=True``. Bin size can be changed by ``bins`
255
264
plt.figure();
256
265
257
266
@savefig hist_new_stacked.png
258
- df4.plot( kind = ' hist' , stacked = True , bins = 20 )
267
+ df4.plot. hist( stacked = True , bins = 20 )
259
268
260
269
.. ipython :: python
261
270
:suppress:
@@ -269,7 +278,7 @@ You can pass other keywords supported by matplotlib ``hist``. For example, horiz
269
278
plt.figure();
270
279
271
280
@savefig hist_new_kwargs.png
272
- df4[' a' ].plot( kind = ' hist' , orientation = ' horizontal' , cumulative = True )
281
+ df4[' a' ].plot. hist( orientation = ' horizontal' , cumulative = True )
273
282
274
283
.. ipython :: python
275
284
:suppress:
@@ -329,12 +338,10 @@ The ``by`` keyword can be specified to plot grouped histograms:
329
338
Box Plots
330
339
~~~~~~~~~
331
340
332
- Boxplot can be drawn calling a ``Series `` and ``DataFrame.plot `` with ``kind='box' ``,
333
- or ``DataFrame.boxplot `` to visualize the distribution of values within each column.
334
-
335
341
.. versionadded :: 0.15.0
336
342
337
- ``plot `` method now supports ``kind='box' `` to draw boxplot.
343
+ Boxplot can be drawn calling :meth: `Series.plot.box ` and :meth: `DataFrame.plot.box `,
344
+ or :meth: `DataFrame.boxplot ` to visualize the distribution of values within each column.
338
345
339
346
For instance, here is a boxplot representing five trials of 10 observations of
340
347
a uniform random variable on [0,1).
@@ -350,7 +357,7 @@ a uniform random variable on [0,1).
350
357
df = pd.DataFrame(np.random.rand(10 , 5 ), columns = [' A' , ' B' , ' C' , ' D' , ' E' ])
351
358
352
359
@savefig box_plot_new.png
353
- df.plot( kind = ' box' )
360
+ df.plot. box( )
354
361
355
362
Boxplot can be colorized by passing ``color `` keyword. You can pass a ``dict ``
356
363
whose keys are ``boxes ``, ``whiskers ``, ``medians `` and ``caps ``.
@@ -371,7 +378,7 @@ more complicated colorization, you can get each drawn artists by passing
371
378
medians = ' DarkBlue' , caps = ' Gray' )
372
379
373
380
@savefig box_new_colorize.png
374
- df.plot( kind = ' box' , color = color, sym = ' r+' )
381
+ df.plot. box( color = color, sym = ' r+' )
375
382
376
383
.. ipython :: python
377
384
:suppress:
@@ -385,7 +392,7 @@ For example, horizontal and custom-positioned boxplot can be drawn by
385
392
.. ipython :: python
386
393
387
394
@savefig box_new_kwargs.png
388
- df.plot( kind = ' box' , vert = False , positions = [1 , 4 , 5 , 6 , 8 ])
395
+ df.plot. box( vert = False , positions = [1 , 4 , 5 , 6 , 8 ])
389
396
390
397
391
398
See the :meth: `boxplot <matplotlib.axes.Axes.boxplot> ` method and the
@@ -464,7 +471,7 @@ When ``subplots=False`` / ``by`` is ``None``:
464
471
465
472
* if ``return_type `` is ``'dict' ``, a dictionary containing the :class: `matplotlib Lines <matplotlib.lines.Line2D> ` is returned. The keys are "boxes", "caps", "fliers", "medians", and "whiskers".
466
473
This is the default of ``boxplot `` in historical reason.
467
- Note that ``plot(kind=' box' ) `` returns ``Axes `` as default as the same as other plots.
474
+ Note that ``plot. box( ) `` returns ``Axes `` by default same as other plots.
468
475
* if ``return_type `` is ``'axes' ``, a :class: `matplotlib Axes <matplotlib.axes.Axes> ` containing the boxplot is returned.
469
476
* if ``return_type `` is ``'both' `` a namedtuple containing the :class: `matplotlib Axes <matplotlib.axes.Axes> `
470
477
and :class: `matplotlib Lines <matplotlib.lines.Line2D> ` is returned
@@ -516,7 +523,8 @@ Area Plot
516
523
517
524
.. versionadded :: 0.14
518
525
519
- You can create area plots with ``Series.plot `` and ``DataFrame.plot `` by passing ``kind='area' ``. Area plots are stacked by default. To produce stacked area plot, each column must be either all positive or all negative values.
526
+ You can create area plots with :meth: `Series.plot.area ` and :meth: `DataFrame.plot.area `.
527
+ Area plots are stacked by default. To produce stacked area plot, each column must be either all positive or all negative values.
520
528
521
529
When input data contains `NaN `, it will be automatically filled by 0. If you want to drop or fill by different values, use :func: `dataframe.dropna ` or :func: `dataframe.fillna ` before calling `plot `.
522
530
@@ -531,7 +539,7 @@ When input data contains `NaN`, it will be automatically filled by 0. If you wan
531
539
df = pd.DataFrame(np.random.rand(10 , 4 ), columns = [' a' , ' b' , ' c' , ' d' ])
532
540
533
541
@savefig area_plot_stacked.png
534
- df.plot( kind = ' area' );
542
+ df.plot. area( );
535
543
536
544
To produce an unstacked plot, pass ``stacked=False ``. Alpha value is set to 0.5 unless otherwise specified:
537
545
@@ -544,7 +552,7 @@ To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5
544
552
.. ipython :: python
545
553
546
554
@savefig area_plot_unstacked.png
547
- df.plot( kind = ' area' , stacked = False );
555
+ df.plot. area( stacked = False );
548
556
549
557
.. _visualization.scatter :
550
558
@@ -553,7 +561,7 @@ Scatter Plot
553
561
554
562
.. versionadded :: 0.13
555
563
556
- You can create scatter plots with `` DataFrame.plot `` by passing `` kind=' scatter' `` .
564
+ Scatter plot can be drawn by using the :meth: ` DataFrame.plot. scatter ` method .
557
565
Scatter plot requires numeric columns for x and y axis.
558
566
These can be specified by ``x `` and ``y `` keywords each.
559
567
@@ -569,18 +577,16 @@ These can be specified by ``x`` and ``y`` keywords each.
569
577
df = pd.DataFrame(np.random.rand(50 , 4 ), columns = [' a' , ' b' , ' c' , ' d' ])
570
578
571
579
@savefig scatter_plot.png
572
- df.plot( kind = ' scatter' , x = ' a' , y = ' b' );
580
+ df.plot. scatter( x = ' a' , y = ' b' );
573
581
574
582
To plot multiple column groups in a single axes, repeat ``plot `` method specifying target ``ax ``.
575
583
It is recommended to specify ``color `` and ``label `` keywords to distinguish each groups.
576
584
577
585
.. ipython :: python
578
586
579
- ax = df.plot(kind = ' scatter' , x = ' a' , y = ' b' ,
580
- color = ' DarkBlue' , label = ' Group 1' );
587
+ ax = df.plot.scatter(x = ' a' , y = ' b' , color = ' DarkBlue' , label = ' Group 1' );
581
588
@savefig scatter_plot_repeated.png
582
- df.plot(kind = ' scatter' , x = ' c' , y = ' d' ,
583
- color = ' DarkGreen' , label = ' Group 2' , ax = ax);
589
+ df.plot.scatter(x = ' c' , y = ' d' , color = ' DarkGreen' , label = ' Group 2' , ax = ax);
584
590
585
591
.. ipython :: python
586
592
:suppress:
@@ -593,7 +599,7 @@ each point:
593
599
.. ipython :: python
594
600
595
601
@savefig scatter_plot_colored.png
596
- df.plot( kind = ' scatter' , x = ' a' , y = ' b' , c = ' c' , s = 50 );
602
+ df.plot. scatter( x = ' a' , y = ' b' , c = ' c' , s = 50 );
597
603
598
604
599
605
.. ipython :: python
@@ -607,7 +613,7 @@ Below example shows a bubble chart using a dataframe column values as bubble siz
607
613
.. ipython :: python
608
614
609
615
@savefig scatter_plot_bubble.png
610
- df.plot( kind = ' scatter' , x = ' a' , y = ' b' , s = df[' c' ]* 200 );
616
+ df.plot. scatter( x = ' a' , y = ' b' , s = df[' c' ]* 200 );
611
617
612
618
.. ipython :: python
613
619
:suppress:
@@ -624,8 +630,7 @@ Hexagonal Bin Plot
624
630
625
631
.. versionadded :: 0.14
626
632
627
- You can create hexagonal bin plots with :meth: `DataFrame.plot ` and
628
- ``kind='hexbin' ``.
633
+ You can create hexagonal bin plots with :meth: `DataFrame.plot.hexbin `.
629
634
Hexbin plots can be a useful alternative to scatter plots if your data are
630
635
too dense to plot each point individually.
631
636
@@ -641,7 +646,7 @@ too dense to plot each point individually.
641
646
df[' b' ] = df[' b' ] + np.arange(1000 )
642
647
643
648
@savefig hexbin_plot.png
644
- df.plot( kind = ' hexbin' , x = ' a' , y = ' b' , gridsize = 25 )
649
+ df.plot. hexbin( x = ' a' , y = ' b' , gridsize = 25 )
645
650
646
651
647
652
A useful keyword argument is ``gridsize ``; it controls the number of hexagons
@@ -670,7 +675,7 @@ given by column ``z``. The bins are aggregated with numpy's ``max`` function.
670
675
df[' z' ] = np.random.uniform(0 , 3 , 1000 )
671
676
672
677
@savefig hexbin_plot_agg.png
673
- df.plot( kind = ' hexbin' , x = ' a' , y = ' b' , C = ' z' , reduce_C_function = np.max,
678
+ df.plot. hexbin( x = ' a' , y = ' b' , C = ' z' , reduce_C_function = np.max,
674
679
gridsize = 25 )
675
680
676
681
.. ipython :: python
@@ -688,7 +693,7 @@ Pie plot
688
693
689
694
.. versionadded :: 0.14
690
695
691
- You can create a pie plot with :meth: `DataFrame.plot ` or :meth: `Series.plot ` with `` kind=' pie' ` `.
696
+ You can create a pie plot with :meth: `DataFrame.plot.pie ` or :meth: `Series.plot. pie `.
692
697
If your data includes any ``NaN ``, they will be automatically filled with 0.
693
698
A ``ValueError `` will be raised if there are any negative values in your data.
694
699
@@ -703,7 +708,7 @@ A ``ValueError`` will be raised if there are any negative values in your data.
703
708
series = pd.Series(3 * np.random.rand(4 ), index = [' a' , ' b' , ' c' , ' d' ], name = ' series' )
704
709
705
710
@savefig series_pie_plot.png
706
- series.plot( kind = ' pie' , figsize = (6 , 6 ))
711
+ series.plot. pie( figsize = (6 , 6 ))
707
712
708
713
.. ipython :: python
709
714
:suppress:
@@ -730,7 +735,7 @@ A legend will be drawn in each pie plots by default; specify ``legend=False`` to
730
735
df = pd.DataFrame(3 * np.random.rand(4 , 2 ), index = [' a' , ' b' , ' c' , ' d' ], columns = [' x' , ' y' ])
731
736
732
737
@savefig df_pie_plot.png
733
- df.plot( kind = ' pie' , subplots = True , figsize = (8 , 4 ))
738
+ df.plot. pie( subplots = True , figsize = (8 , 4 ))
734
739
735
740
.. ipython :: python
736
741
:suppress:
@@ -757,8 +762,8 @@ Also, other keywords supported by :func:`matplotlib.pyplot.pie` can be used.
757
762
.. ipython :: python
758
763
759
764
@savefig series_pie_plot_options.png
760
- series.plot( kind = ' pie' , labels = [' AA' , ' BB' , ' CC' , ' DD' ], colors = [' r' , ' g' , ' b' , ' c' ],
761
- autopct = ' %.2f ' , fontsize = 20 , figsize = (6 , 6 ))
765
+ series.plot. pie( labels = [' AA' , ' BB' , ' CC' , ' DD' ], colors = [' r' , ' g' , ' b' , ' c' ],
766
+ autopct = ' %.2f ' , fontsize = 20 , figsize = (6 , 6 ))
762
767
763
768
If you pass values whose sum total is less than 1.0, matplotlib draws a semicircle.
764
769
@@ -773,7 +778,7 @@ If you pass values whose sum total is less than 1.0, matplotlib draws a semicirc
773
778
series = pd.Series([0.1 ] * 4 , index = [' a' , ' b' , ' c' , ' d' ], name = ' series2' )
774
779
775
780
@savefig series_pie_plot_semi.png
776
- series.plot( kind = ' pie' , figsize = (6 , 6 ))
781
+ series.plot. pie( figsize = (6 , 6 ))
777
782
778
783
See the `matplotlib pie documentation <http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.pie >`__ for more.
779
784
@@ -863,8 +868,7 @@ Density Plot
863
868
864
869
.. versionadded :: 0.8.0
865
870
866
- You can create density plots using the Series/DataFrame.plot and
867
- setting ``kind='kde' ``:
871
+ You can create density plots using the :meth: `Series.plot.kde ` and :meth: `DataFrame.plot.kde ` methods.
868
872
869
873
.. ipython :: python
870
874
:suppress:
@@ -877,7 +881,7 @@ setting ``kind='kde'``:
877
881
ser = pd.Series(np.random.randn(1000 ))
878
882
879
883
@savefig kde_plot.png
880
- ser.plot( kind = ' kde' )
884
+ ser.plot. kde( )
881
885
882
886
.. ipython :: python
883
887
:suppress:
@@ -1392,7 +1396,7 @@ Here is an example of one way to easily plot group means with standard deviation
1392
1396
# Plot
1393
1397
fig, ax = plt.subplots()
1394
1398
@savefig errorbar_example.png
1395
- means.plot(yerr = errors, ax = ax, kind = ' bar ' )
1399
+ means.plot.bar (yerr = errors, ax = ax)
1396
1400
1397
1401
.. ipython :: python
1398
1402
:suppress:
@@ -1532,7 +1536,7 @@ Colormaps can also be used other plot types, like bar charts:
1532
1536
plt.figure()
1533
1537
1534
1538
@savefig greens.png
1535
- dd.plot( kind = ' bar' , colormap = ' Greens' )
1539
+ dd.plot. bar( colormap = ' Greens' )
1536
1540
1537
1541
.. ipython :: python
1538
1542
:suppress:
0 commit comments