Skip to content

Commit 2ce897f

Browse files
Moisanjreback
authored andcommitted
DOC Use plot.<kind> instead of plot(kind=<kind>) GH11043
closes #11043 I modified the visualization documentation to use plot.<kind> instead of plot(kind=<kind>) in the examples as explained by [issue 11043](#11043). Author: Thierry Moisan <[email protected]> Closes #11303 from Moisan/remove_plot_kind and squashes the following commits: 1f75ee7 [Thierry Moisan] Remove the unneeded version tags e08d4fc [Thierry Moisan] Fix the scatter plot description 8d96ed2 [Thierry Moisan] Fix the indentations and keep an example with plot(kind=<kind>) 9042526 [Thierry Moisan] DOC Use plot.<kind> instead of plot(kind=<kind>) GH11043
1 parent a424bb2 commit 2ce897f

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

doc/source/visualization.rst

+49-45
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,16 @@ These include:
135135
* :ref:`'hexbin' <visualization.hexbin>` for hexagonal bin plots
136136
* :ref:`'pie' <visualization.pie>` for pie plots
137137

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
139148

140149
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:
141150

@@ -178,9 +187,9 @@ For labeled, non-time series data, you may wish to produce a bar plot:
178187
plt.figure();
179188
180189
@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')
182191
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
184193
bar plot:
185194

186195
.. ipython:: python
@@ -195,7 +204,7 @@ bar plot:
195204
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
196205
197206
@savefig bar_plot_multi_ex.png
198-
df2.plot(kind='bar');
207+
df2.plot.bar();
199208
200209
To produce a stacked bar plot, pass ``stacked=True``:
201210

@@ -208,9 +217,9 @@ To produce a stacked bar plot, pass ``stacked=True``:
208217
.. ipython:: python
209218
210219
@savefig bar_plot_stacked_ex.png
211-
df2.plot(kind='bar', stacked=True);
220+
df2.plot.bar(stacked=True);
212221
213-
To get horizontal bar plots, pass ``kind='barh'``:
222+
To get horizontal bar plots, use the ``barh`` method:
214223

215224
.. ipython:: python
216225
:suppress:
@@ -221,7 +230,7 @@ To get horizontal bar plots, pass ``kind='barh'``:
221230
.. ipython:: python
222231
223232
@savefig barh_plot_stacked_ex.png
224-
df2.plot(kind='barh', stacked=True);
233+
df2.plot.barh(stacked=True);
225234
226235
.. _visualization.hist:
227236

@@ -230,7 +239,7 @@ Histograms
230239

231240
.. versionadded:: 0.15.0
232241

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.
234243

235244
.. ipython:: python
236245
@@ -240,7 +249,7 @@ Histogram can be drawn specifying ``kind='hist'``.
240249
plt.figure();
241250
242251
@savefig hist_new.png
243-
df4.plot(kind='hist', alpha=0.5)
252+
df4.plot.hist(alpha=0.5)
244253
245254
246255
.. ipython:: python
@@ -255,7 +264,7 @@ Histogram can be stacked by ``stacked=True``. Bin size can be changed by ``bins`
255264
plt.figure();
256265
257266
@savefig hist_new_stacked.png
258-
df4.plot(kind='hist', stacked=True, bins=20)
267+
df4.plot.hist(stacked=True, bins=20)
259268
260269
.. ipython:: python
261270
:suppress:
@@ -269,7 +278,7 @@ You can pass other keywords supported by matplotlib ``hist``. For example, horiz
269278
plt.figure();
270279
271280
@savefig hist_new_kwargs.png
272-
df4['a'].plot(kind='hist', orientation='horizontal', cumulative=True)
281+
df4['a'].plot.hist(orientation='horizontal', cumulative=True)
273282
274283
.. ipython:: python
275284
:suppress:
@@ -329,12 +338,10 @@ The ``by`` keyword can be specified to plot grouped histograms:
329338
Box Plots
330339
~~~~~~~~~
331340

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-
335341
.. versionadded:: 0.15.0
336342

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.
338345

339346
For instance, here is a boxplot representing five trials of 10 observations of
340347
a uniform random variable on [0,1).
@@ -350,7 +357,7 @@ a uniform random variable on [0,1).
350357
df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
351358
352359
@savefig box_plot_new.png
353-
df.plot(kind='box')
360+
df.plot.box()
354361
355362
Boxplot can be colorized by passing ``color`` keyword. You can pass a ``dict``
356363
whose keys are ``boxes``, ``whiskers``, ``medians`` and ``caps``.
@@ -371,7 +378,7 @@ more complicated colorization, you can get each drawn artists by passing
371378
medians='DarkBlue', caps='Gray')
372379
373380
@savefig box_new_colorize.png
374-
df.plot(kind='box', color=color, sym='r+')
381+
df.plot.box(color=color, sym='r+')
375382
376383
.. ipython:: python
377384
:suppress:
@@ -385,7 +392,7 @@ For example, horizontal and custom-positioned boxplot can be drawn by
385392
.. ipython:: python
386393
387394
@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])
389396
390397
391398
See the :meth:`boxplot <matplotlib.axes.Axes.boxplot>` method and the
@@ -464,7 +471,7 @@ When ``subplots=False`` / ``by`` is ``None``:
464471

465472
* 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".
466473
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.
468475
* if ``return_type`` is ``'axes'``, a :class:`matplotlib Axes <matplotlib.axes.Axes>` containing the boxplot is returned.
469476
* if ``return_type`` is ``'both'`` a namedtuple containing the :class:`matplotlib Axes <matplotlib.axes.Axes>`
470477
and :class:`matplotlib Lines <matplotlib.lines.Line2D>` is returned
@@ -516,7 +523,8 @@ Area Plot
516523

517524
.. versionadded:: 0.14
518525

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.
520528

521529
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`.
522530

@@ -531,7 +539,7 @@ When input data contains `NaN`, it will be automatically filled by 0. If you wan
531539
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
532540
533541
@savefig area_plot_stacked.png
534-
df.plot(kind='area');
542+
df.plot.area();
535543
536544
To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5 unless otherwise specified:
537545

@@ -544,7 +552,7 @@ To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5
544552
.. ipython:: python
545553
546554
@savefig area_plot_unstacked.png
547-
df.plot(kind='area', stacked=False);
555+
df.plot.area(stacked=False);
548556
549557
.. _visualization.scatter:
550558

@@ -553,7 +561,7 @@ Scatter Plot
553561

554562
.. versionadded:: 0.13
555563

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.
557565
Scatter plot requires numeric columns for x and y axis.
558566
These can be specified by ``x`` and ``y`` keywords each.
559567

@@ -569,18 +577,16 @@ These can be specified by ``x`` and ``y`` keywords each.
569577
df = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])
570578
571579
@savefig scatter_plot.png
572-
df.plot(kind='scatter', x='a', y='b');
580+
df.plot.scatter(x='a', y='b');
573581
574582
To plot multiple column groups in a single axes, repeat ``plot`` method specifying target ``ax``.
575583
It is recommended to specify ``color`` and ``label`` keywords to distinguish each groups.
576584

577585
.. ipython:: python
578586
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');
581588
@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);
584590
585591
.. ipython:: python
586592
:suppress:
@@ -593,7 +599,7 @@ each point:
593599
.. ipython:: python
594600
595601
@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);
597603
598604
599605
.. ipython:: python
@@ -607,7 +613,7 @@ Below example shows a bubble chart using a dataframe column values as bubble siz
607613
.. ipython:: python
608614
609615
@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);
611617
612618
.. ipython:: python
613619
:suppress:
@@ -624,8 +630,7 @@ Hexagonal Bin Plot
624630

625631
.. versionadded:: 0.14
626632

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`.
629634
Hexbin plots can be a useful alternative to scatter plots if your data are
630635
too dense to plot each point individually.
631636

@@ -641,7 +646,7 @@ too dense to plot each point individually.
641646
df['b'] = df['b'] + np.arange(1000)
642647
643648
@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)
645650
646651
647652
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.
670675
df['z'] = np.random.uniform(0, 3, 1000)
671676
672677
@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,
674679
gridsize=25)
675680
676681
.. ipython:: python
@@ -688,7 +693,7 @@ Pie plot
688693

689694
.. versionadded:: 0.14
690695

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`.
692697
If your data includes any ``NaN``, they will be automatically filled with 0.
693698
A ``ValueError`` will be raised if there are any negative values in your data.
694699

@@ -703,7 +708,7 @@ A ``ValueError`` will be raised if there are any negative values in your data.
703708
series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
704709
705710
@savefig series_pie_plot.png
706-
series.plot(kind='pie', figsize=(6, 6))
711+
series.plot.pie(figsize=(6, 6))
707712
708713
.. ipython:: python
709714
:suppress:
@@ -730,7 +735,7 @@ A legend will be drawn in each pie plots by default; specify ``legend=False`` to
730735
df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
731736
732737
@savefig df_pie_plot.png
733-
df.plot(kind='pie', subplots=True, figsize=(8, 4))
738+
df.plot.pie(subplots=True, figsize=(8, 4))
734739
735740
.. ipython:: python
736741
:suppress:
@@ -757,8 +762,8 @@ Also, other keywords supported by :func:`matplotlib.pyplot.pie` can be used.
757762
.. ipython:: python
758763
759764
@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))
762767
763768
If you pass values whose sum total is less than 1.0, matplotlib draws a semicircle.
764769

@@ -773,7 +778,7 @@ If you pass values whose sum total is less than 1.0, matplotlib draws a semicirc
773778
series = pd.Series([0.1] * 4, index=['a', 'b', 'c', 'd'], name='series2')
774779
775780
@savefig series_pie_plot_semi.png
776-
series.plot(kind='pie', figsize=(6, 6))
781+
series.plot.pie(figsize=(6, 6))
777782
778783
See the `matplotlib pie documentation <http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.pie>`__ for more.
779784

@@ -863,8 +868,7 @@ Density Plot
863868

864869
.. versionadded:: 0.8.0
865870

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.
868872

869873
.. ipython:: python
870874
:suppress:
@@ -877,7 +881,7 @@ setting ``kind='kde'``:
877881
ser = pd.Series(np.random.randn(1000))
878882
879883
@savefig kde_plot.png
880-
ser.plot(kind='kde')
884+
ser.plot.kde()
881885
882886
.. ipython:: python
883887
:suppress:
@@ -1392,7 +1396,7 @@ Here is an example of one way to easily plot group means with standard deviation
13921396
# Plot
13931397
fig, ax = plt.subplots()
13941398
@savefig errorbar_example.png
1395-
means.plot(yerr=errors, ax=ax, kind='bar')
1399+
means.plot.bar(yerr=errors, ax=ax)
13961400
13971401
.. ipython:: python
13981402
:suppress:
@@ -1532,7 +1536,7 @@ Colormaps can also be used other plot types, like bar charts:
15321536
plt.figure()
15331537
15341538
@savefig greens.png
1535-
dd.plot(kind='bar', colormap='Greens')
1539+
dd.plot.bar(colormap='Greens')
15361540
15371541
.. ipython:: python
15381542
:suppress:

0 commit comments

Comments
 (0)