Skip to content

Commit f1c0b7c

Browse files
delkk0TomAugspurger
authored andcommitted
DOC: Improved the docstring of pandas.plotting._core.FramePlotMethods… (pandas-dev#20157)
* DOC: Improved the docstring of pandas.plotting._core.FramePlotMethods.barh() - Added examples section - Added extended summary - Added argument explanation * DOC: Improved the docstring of pandas.plotting._core.FramePlotMethods.barh() - Correcting PR comments * DOC: Improved the docstring of pandas.plotting._core.FramePlotMethods.barh() - Adding defaults for variables. * Update reference
1 parent 0780193 commit f1c0b7c

File tree

1 file changed

+86
-24
lines changed

1 file changed

+86
-24
lines changed

pandas/plotting/_core.py

+86-24
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ def orientation(self):
14091409
14101410
Returns
14111411
-------
1412-
axes : matplotlib.AxesSubplot or np.array of them
1412+
axes : matplotlib.axes.Axes or numpy.ndarray of them
14131413
14141414
See Also
14151415
--------
@@ -1917,7 +1917,7 @@ def _plot(data, x=None, y=None, subplots=False,
19171917
19181918
Returns
19191919
-------
1920-
axes : matplotlib.AxesSubplot or np.array of them
1920+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
19211921
19221922
Notes
19231923
-----
@@ -2581,7 +2581,7 @@ def line(self, **kwds):
25812581
25822582
Returns
25832583
-------
2584-
axes : matplotlib.AxesSubplot or np.array of them
2584+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
25852585
25862586
Examples
25872587
--------
@@ -2606,7 +2606,7 @@ def bar(self, **kwds):
26062606
26072607
Returns
26082608
-------
2609-
axes : matplotlib.AxesSubplot or np.array of them
2609+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
26102610
"""
26112611
return self(kind='bar', **kwds)
26122612

@@ -2622,7 +2622,7 @@ def barh(self, **kwds):
26222622
26232623
Returns
26242624
-------
2625-
axes : matplotlib.AxesSubplot or np.array of them
2625+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
26262626
"""
26272627
return self(kind='barh', **kwds)
26282628

@@ -2638,7 +2638,7 @@ def box(self, **kwds):
26382638
26392639
Returns
26402640
-------
2641-
axes : matplotlib.AxesSubplot or np.array of them
2641+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
26422642
"""
26432643
return self(kind='box', **kwds)
26442644

@@ -2656,7 +2656,7 @@ def hist(self, bins=10, **kwds):
26562656
26572657
Returns
26582658
-------
2659-
axes : matplotlib.AxesSubplot or np.array of them
2659+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
26602660
"""
26612661
return self(kind='hist', bins=bins, **kwds)
26622662

@@ -2715,7 +2715,7 @@ def area(self, **kwds):
27152715
27162716
Returns
27172717
-------
2718-
axes : matplotlib.AxesSubplot or np.array of them
2718+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
27192719
"""
27202720
return self(kind='area', **kwds)
27212721

@@ -2731,7 +2731,7 @@ def pie(self, **kwds):
27312731
27322732
Returns
27332733
-------
2734-
axes : matplotlib.AxesSubplot or np.array of them
2734+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
27352735
"""
27362736
return self(kind='pie', **kwds)
27372737

@@ -2783,7 +2783,7 @@ def line(self, x=None, y=None, **kwds):
27832783
27842784
Returns
27852785
-------
2786-
axes : matplotlib.AxesSubplot or np.array of them
2786+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
27872787
"""
27882788
return self(kind='line', x=x, y=y, **kwds)
27892789

@@ -2801,25 +2801,87 @@ def bar(self, x=None, y=None, **kwds):
28012801
28022802
Returns
28032803
-------
2804-
axes : matplotlib.AxesSubplot or np.array of them
2804+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
28052805
"""
28062806
return self(kind='bar', x=x, y=y, **kwds)
28072807

28082808
def barh(self, x=None, y=None, **kwds):
28092809
"""
2810-
Horizontal bar plot
2810+
Make a horizontal bar plot.
2811+
2812+
A horizontal bar plot is a plot that presents quantitative data with
2813+
rectangular bars with lengths proportional to the values that they
2814+
represent. A bar plot shows comparisons among discrete categories. One
2815+
axis of the plot shows the specific categories being compared, and the
2816+
other axis represents a measured value.
28112817
28122818
Parameters
28132819
----------
2814-
x, y : label or position, optional
2815-
Coordinates for each point.
2816-
`**kwds` : optional
2817-
Additional keyword arguments are documented in
2818-
:meth:`pandas.DataFrame.plot`.
2820+
x : label or position, default DataFrame.index
2821+
Column to be used for categories.
2822+
y : label or position, default All numeric columns in dataframe
2823+
Columns to be plotted from the DataFrame.
2824+
**kwds
2825+
Keyword arguments to pass on to :meth:`pandas.DataFrame.plot`.
28192826
28202827
Returns
28212828
-------
2822-
axes : matplotlib.AxesSubplot or np.array of them
2829+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them.
2830+
2831+
See Also
2832+
--------
2833+
pandas.DataFrame.plot.bar: Vertical bar plot.
2834+
pandas.DataFrame.plot : Make plots of DataFrame using matplotlib.
2835+
matplotlib.axes.Axes.bar : Plot a vertical bar plot using matplotlib.
2836+
2837+
Examples
2838+
--------
2839+
Basic example
2840+
2841+
.. plot::
2842+
:context: close-figs
2843+
2844+
>>> df = pd.DataFrame({'lab':['A', 'B', 'C'], 'val':[10, 30, 20]})
2845+
>>> ax = df.plot.barh(x='lab', y='val')
2846+
2847+
Plot a whole DataFrame to a horizontal bar plot
2848+
2849+
.. plot::
2850+
:context: close-figs
2851+
2852+
>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
2853+
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
2854+
>>> index = ['snail', 'pig', 'elephant',
2855+
... 'rabbit', 'giraffe', 'coyote', 'horse']
2856+
>>> df = pd.DataFrame({'speed': speed,
2857+
... 'lifespan': lifespan}, index=index)
2858+
>>> ax = df.plot.barh()
2859+
2860+
Plot a column of the DataFrame to a horizontal bar plot
2861+
2862+
.. plot::
2863+
:context: close-figs
2864+
2865+
>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
2866+
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
2867+
>>> index = ['snail', 'pig', 'elephant',
2868+
... 'rabbit', 'giraffe', 'coyote', 'horse']
2869+
>>> df = pd.DataFrame({'speed': speed,
2870+
... 'lifespan': lifespan}, index=index)
2871+
>>> ax = df.plot.barh(y='speed')
2872+
2873+
Plot DataFrame versus the desired column
2874+
2875+
.. plot::
2876+
:context: close-figs
2877+
2878+
>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
2879+
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
2880+
>>> index = ['snail', 'pig', 'elephant',
2881+
... 'rabbit', 'giraffe', 'coyote', 'horse']
2882+
>>> df = pd.DataFrame({'speed': speed,
2883+
... 'lifespan': lifespan}, index=index)
2884+
>>> ax = df.plot.barh(x='lifespan')
28232885
"""
28242886
return self(kind='barh', x=x, y=y, **kwds)
28252887

@@ -2837,7 +2899,7 @@ def box(self, by=None, **kwds):
28372899
28382900
Returns
28392901
-------
2840-
axes : matplotlib.AxesSubplot or np.array of them
2902+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
28412903
"""
28422904
return self(kind='box', by=by, **kwds)
28432905

@@ -2857,7 +2919,7 @@ def hist(self, by=None, bins=10, **kwds):
28572919
28582920
Returns
28592921
-------
2860-
axes : matplotlib.AxesSubplot or np.array of them
2922+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
28612923
"""
28622924
return self(kind='hist', by=by, bins=bins, **kwds)
28632925

@@ -2921,7 +2983,7 @@ def area(self, x=None, y=None, **kwds):
29212983
29222984
Returns
29232985
-------
2924-
axes : matplotlib.AxesSubplot or np.array of them
2986+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
29252987
"""
29262988
return self(kind='area', x=x, y=y, **kwds)
29272989

@@ -2939,7 +3001,7 @@ def pie(self, y=None, **kwds):
29393001
29403002
Returns
29413003
-------
2942-
axes : matplotlib.AxesSubplot or np.array of them
3004+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
29433005
"""
29443006
return self(kind='pie', y=y, **kwds)
29453007

@@ -2961,7 +3023,7 @@ def scatter(self, x, y, s=None, c=None, **kwds):
29613023
29623024
Returns
29633025
-------
2964-
axes : matplotlib.AxesSubplot or np.array of them
3026+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
29653027
"""
29663028
return self(kind='scatter', x=x, y=y, c=c, s=s, **kwds)
29673029

@@ -2987,7 +3049,7 @@ def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None,
29873049
29883050
Returns
29893051
-------
2990-
axes : matplotlib.AxesSubplot or np.array of them
3052+
axes : :class:`matplotlib.axes.Axes` or numpy.ndarray of them
29913053
"""
29923054
if reduce_C_function is not None:
29933055
kwds['reduce_C_function'] = reduce_C_function

0 commit comments

Comments
 (0)