Skip to content

Commit 9042526

Browse files
committed
DOC Use plot.<kind> instead of plot(kind=<kind>) GH11043
1 parent c2aa6a2 commit 9042526

File tree

1 file changed

+60
-32
lines changed

1 file changed

+60
-32
lines changed

doc/source/visualization.rst

+60-32
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ For labeled, non-time series data, you may wish to produce a bar plot:
178178
plt.figure();
179179
180180
@savefig bar_plot_ex.png
181-
df.ix[5].plot(kind='bar'); plt.axhline(0, color='k')
181+
df.ix[5].plot.bar(); plt.axhline(0, color='k')
182182
183-
Calling a DataFrame's :meth:`~DataFrame.plot` method with ``kind='bar'`` produces a multiple
183+
Calling a DataFrame's :meth:`~DataFrame.plot.bar` method produces a multiple
184184
bar plot:
185185

186186
.. ipython:: python
@@ -195,7 +195,7 @@ bar plot:
195195
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
196196
197197
@savefig bar_plot_multi_ex.png
198-
df2.plot(kind='bar');
198+
df2.plot.bar();
199199
200200
To produce a stacked bar plot, pass ``stacked=True``:
201201

@@ -208,9 +208,9 @@ To produce a stacked bar plot, pass ``stacked=True``:
208208
.. ipython:: python
209209
210210
@savefig bar_plot_stacked_ex.png
211-
df2.plot(kind='bar', stacked=True);
211+
df2.plot.bar(stacked=True);
212212
213-
To get horizontal bar plots, pass ``kind='barh'``:
213+
To get horizontal bar plots, use the ``barh`` method:
214214

215215
.. ipython:: python
216216
:suppress:
@@ -221,16 +221,20 @@ To get horizontal bar plots, pass ``kind='barh'``:
221221
.. ipython:: python
222222
223223
@savefig barh_plot_stacked_ex.png
224-
df2.plot(kind='barh', stacked=True);
224+
df2.plot.barh(stacked=True);
225225
226226
.. _visualization.hist:
227227

228228
Histograms
229229
~~~~~~~~~~
230230

231+
.. versionadded:: 0.17.0
232+
233+
Histogram can be drawn by using the :meth:`DataFrame.plot.hist` and :meth:`Series.plot.hist` methods.
234+
231235
.. versionadded:: 0.15.0
232236

233-
Histogram can be drawn specifying ``kind='hist'``.
237+
Histogram can be drawn by using the ``plot(kind='hist')`` method.
234238

235239
.. ipython:: python
236240
@@ -240,7 +244,7 @@ Histogram can be drawn specifying ``kind='hist'``.
240244
plt.figure();
241245
242246
@savefig hist_new.png
243-
df4.plot(kind='hist', alpha=0.5)
247+
df4.plot.hist(alpha=0.5)
244248
245249
246250
.. ipython:: python
@@ -255,7 +259,7 @@ Histogram can be stacked by ``stacked=True``. Bin size can be changed by ``bins`
255259
plt.figure();
256260
257261
@savefig hist_new_stacked.png
258-
df4.plot(kind='hist', stacked=True, bins=20)
262+
df4.plot.hist(stacked=True, bins=20)
259263
260264
.. ipython:: python
261265
:suppress:
@@ -269,7 +273,7 @@ You can pass other keywords supported by matplotlib ``hist``. For example, horiz
269273
plt.figure();
270274
271275
@savefig hist_new_kwargs.png
272-
df4['a'].plot(kind='hist', orientation='horizontal', cumulative=True)
276+
df4['a'].plot.hist(orientation='horizontal', cumulative=True)
273277
274278
.. ipython:: python
275279
:suppress:
@@ -329,8 +333,12 @@ The ``by`` keyword can be specified to plot grouped histograms:
329333
Box Plots
330334
~~~~~~~~~
331335

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.
336+
Boxplot can be drawn calling :meth:`Series.plot.box` and :meth:`DataFrame.plot.box`,
337+
or :meth:`DataFrame.boxplot` to visualize the distribution of values within each column.
338+
339+
.. versionadded:: 0.17.0
340+
341+
:meth:`DataFrame.plot.box` and :meth:`Series.plot.box` can now be used to draw boxplot.
334342

335343
.. versionadded:: 0.15.0
336344

@@ -350,7 +358,7 @@ a uniform random variable on [0,1).
350358
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
351359
352360
@savefig box_plot_new.png
353-
df.plot(kind='box')
361+
df.plot.box()
354362
355363
Boxplot can be colorized by passing ``color`` keyword. You can pass a ``dict``
356364
whose keys are ``boxes``, ``whiskers``, ``medians`` and ``caps``.
@@ -371,7 +379,7 @@ more complicated colorization, you can get each drawn artists by passing
371379
medians='DarkBlue', caps='Gray')
372380
373381
@savefig box_new_colorize.png
374-
df.plot(kind='box', color=color, sym='r+')
382+
df.plot.box(color=color, sym='r+')
375383
376384
.. ipython:: python
377385
:suppress:
@@ -385,7 +393,7 @@ For example, horizontal and custom-positioned boxplot can be drawn by
385393
.. ipython:: python
386394
387395
@savefig box_new_kwargs.png
388-
df.plot(kind='box', vert=False, positions=[1, 4, 5, 6, 8])
396+
df.plot.box(vert=False, positions=[1, 4, 5, 6, 8])
389397
390398
391399
See the :meth:`boxplot <matplotlib.axes.Axes.boxplot>` method and the
@@ -464,7 +472,7 @@ When ``subplots=False`` / ``by`` is ``None``:
464472

465473
* 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".
466474
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.
475+
Note that both ``plot.box()`` and ``plot(kind'box')`` return ``Axes`` as default as the same as other plots.
468476
* if ``return_type`` is ``'axes'``, a :class:`matplotlib Axes <matplotlib.axes.Axes>` containing the boxplot is returned.
469477
* if ``return_type`` is ``'both'`` a namedtuple containging the :class:`matplotlib Axes <matplotlib.axes.Axes>`
470478
and :class:`matplotlib Lines <matplotlib.lines.Line2D>` is returned
@@ -514,6 +522,10 @@ Compare to:
514522
Area Plot
515523
~~~~~~~~~
516524

525+
.. versionadded:: 0.17
526+
527+
You can create area plots with :meth:`Series.plot.area` and :meth:`DataFrame.plot.area`.
528+
517529
.. versionadded:: 0.14
518530

519531
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.
@@ -531,7 +543,7 @@ When input data contains `NaN`, it will be automatically filled by 0. If you wan
531543
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
532544
533545
@savefig area_plot_stacked.png
534-
df.plot(kind='area');
546+
df.plot.area();
535547
536548
To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5 unless otherwise specified:
537549

@@ -544,13 +556,17 @@ To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5
544556
.. ipython:: python
545557
546558
@savefig area_plot_unstacked.png
547-
df.plot(kind='area', stacked=False);
559+
df.plot.area(stacked=False);
548560
549561
.. _visualization.scatter:
550562

551563
Scatter Plot
552564
~~~~~~~~~~~~
553565

566+
.. versionadded:: 0.17.0
567+
568+
Histogram can be drawn by using the :meth:`DataFrame.plot.scatter` and :meth:`Series.plot.scatter` methods.
569+
554570
.. versionadded:: 0.13
555571

556572
You can create scatter plots with ``DataFrame.plot`` by passing ``kind='scatter'``.
@@ -569,17 +585,17 @@ These can be specified by ``x`` and ``y`` keywords each.
569585
df = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])
570586
571587
@savefig scatter_plot.png
572-
df.plot(kind='scatter', x='a', y='b');
588+
df.plot.scatter(x='a', y='b');
573589
574590
To plot multiple column groups in a single axes, repeat ``plot`` method specifying target ``ax``.
575591
It is recommended to specify ``color`` and ``label`` keywords to distinguish each groups.
576592

577593
.. ipython:: python
578594
579-
ax = df.plot(kind='scatter', x='a', y='b',
595+
ax = df.plot.scatter(x='a', y='b',
580596
color='DarkBlue', label='Group 1');
581597
@savefig scatter_plot_repeated.png
582-
df.plot(kind='scatter', x='c', y='d',
598+
df.plot.scatter(x='c', y='d',
583599
color='DarkGreen', label='Group 2', ax=ax);
584600
585601
.. ipython:: python
@@ -593,7 +609,7 @@ each point:
593609
.. ipython:: python
594610
595611
@savefig scatter_plot_colored.png
596-
df.plot(kind='scatter', x='a', y='b', c='c', s=50);
612+
df.plot.scatter(x='a', y='b', c='c', s=50);
597613
598614
599615
.. ipython:: python
@@ -607,7 +623,7 @@ Below example shows a bubble chart using a dataframe column values as bubble siz
607623
.. ipython:: python
608624
609625
@savefig scatter_plot_bubble.png
610-
df.plot(kind='scatter', x='a', y='b', s=df['c']*200);
626+
df.plot.scatter(x='a', y='b', s=df['c']*200);
611627
612628
.. ipython:: python
613629
:suppress:
@@ -622,6 +638,10 @@ See the :meth:`scatter <matplotlib.axes.Axes.scatter>` method and the
622638
Hexagonal Bin Plot
623639
~~~~~~~~~~~~~~~~~~
624640

641+
.. versionadded:: 0.17.0
642+
643+
You can create hexagonal bin plots with :meth:`DataFrame.plot.hexbin`.
644+
625645
.. versionadded:: 0.14
626646

627647
You can create hexagonal bin plots with :meth:`DataFrame.plot` and
@@ -641,7 +661,7 @@ too dense to plot each point individually.
641661
df['b'] = df['b'] + np.arange(1000)
642662
643663
@savefig hexbin_plot.png
644-
df.plot(kind='hexbin', x='a', y='b', gridsize=25)
664+
df.plot.hexbin(x='a', y='b', gridsize=25)
645665
646666
647667
A useful keyword argument is ``gridsize``; it controls the number of hexagons
@@ -670,7 +690,7 @@ given by column ``z``. The bins are aggregated with numpy's ``max`` function.
670690
df['z'] = np.random.uniform(0, 3, 1000)
671691
672692
@savefig hexbin_plot_agg.png
673-
df.plot(kind='hexbin', x='a', y='b', C='z', reduce_C_function=np.max,
693+
df.plot.hexbin(x='a', y='b', C='z', reduce_C_function=np.max,
674694
gridsize=25)
675695
676696
.. ipython:: python
@@ -686,6 +706,10 @@ See the :meth:`hexbin <matplotlib.axes.Axes.hexbin>` method and the
686706
Pie plot
687707
~~~~~~~~
688708

709+
.. versionadded:: 0.17
710+
711+
You can create a pie plot with :meth:`DataFrame.plot.pie` or :meth:`Series.plot.pie`.
712+
689713
.. versionadded:: 0.14
690714

691715
You can create a pie plot with :meth:`DataFrame.plot` or :meth:`Series.plot` with ``kind='pie'``.
@@ -703,7 +727,7 @@ A ``ValueError`` will be raised if there are any negative values in your data.
703727
series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
704728
705729
@savefig series_pie_plot.png
706-
series.plot(kind='pie', figsize=(6, 6))
730+
series.plot.pie(figsize=(6, 6))
707731
708732
.. ipython:: python
709733
:suppress:
@@ -730,7 +754,7 @@ A legend will be drawn in each pie plots by default; specify ``legend=False`` to
730754
df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
731755
732756
@savefig df_pie_plot.png
733-
df.plot(kind='pie', subplots=True, figsize=(8, 4))
757+
df.plot.pie(subplots=True, figsize=(8, 4))
734758
735759
.. ipython:: python
736760
:suppress:
@@ -757,7 +781,7 @@ Also, other keywords supported by :func:`matplotlib.pyplot.pie` can be used.
757781
.. ipython:: python
758782
759783
@savefig series_pie_plot_options.png
760-
series.plot(kind='pie', labels=['AA', 'BB', 'CC', 'DD'], colors=['r', 'g', 'b', 'c'],
784+
series.plot.pie(labels=['AA', 'BB', 'CC', 'DD'], colors=['r', 'g', 'b', 'c'],
761785
autopct='%.2f', fontsize=20, figsize=(6, 6))
762786
763787
If you pass values whose sum total is less than 1.0, matplotlib draws a semicircle.
@@ -773,7 +797,7 @@ If you pass values whose sum total is less than 1.0, matplotlib draws a semicirc
773797
series = pd.Series([0.1] * 4, index=['a', 'b', 'c', 'd'], name='series2')
774798
775799
@savefig series_pie_plot_semi.png
776-
series.plot(kind='pie', figsize=(6, 6))
800+
series.plot.pie(figsize=(6, 6))
777801
778802
See the `matplotlib pie documentation <http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.pie>`__ for more.
779803

@@ -861,6 +885,10 @@ You can create a scatter plot matrix using the
861885
Density Plot
862886
~~~~~~~~~~~~
863887

888+
.. versionadded:: 0.17.0
889+
890+
You can create density plots using the :meth:`Series.plot.kde` and :meth:`DataFrame.plot.kde` methods.
891+
864892
.. versionadded:: 0.8.0
865893

866894
You can create density plots using the Series/DataFrame.plot and
@@ -877,7 +905,7 @@ setting ``kind='kde'``:
877905
ser = pd.Series(np.random.randn(1000))
878906
879907
@savefig kde_plot.png
880-
ser.plot(kind='kde')
908+
ser.plot.kde()
881909
882910
.. ipython:: python
883911
:suppress:
@@ -1392,7 +1420,7 @@ Here is an example of one way to easily plot group means with standard deviation
13921420
# Plot
13931421
fig, ax = plt.subplots()
13941422
@savefig errorbar_example.png
1395-
means.plot(yerr=errors, ax=ax, kind='bar')
1423+
means.plot.bar(yerr=errors, ax=ax)
13961424
13971425
.. ipython:: python
13981426
:suppress:
@@ -1532,7 +1560,7 @@ Colormaps can also be used other plot types, like bar charts:
15321560
plt.figure()
15331561
15341562
@savefig greens.png
1535-
dd.plot(kind='bar', colormap='Greens')
1563+
dd.plot.bar(colormap='Greens')
15361564
15371565
.. ipython:: python
15381566
:suppress:

0 commit comments

Comments
 (0)