Skip to content

Commit 09a04db

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2339a87 commit 09a04db

File tree

1 file changed

+97
-76
lines changed

1 file changed

+97
-76
lines changed

pandas/plotting/_core.py

Lines changed: 97 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from pandas._config import get_option
1010

11-
1211
from pandas.core.dtypes.common import (
1312
is_integer,
1413
is_list_like,
@@ -593,43 +592,38 @@ def boxplot(
593592
:context: close-figs
594593
595594
>>> np.random.seed(1234)
596-
>>> df = pd.DataFrame(np.random.randn(10, 4),
597-
... columns=['Col1', 'Col2', 'Col3', 'Col4'])
598-
>>> boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3']) # doctest: +SKIP
595+
>>> df = pd.DataFrame(
596+
... np.random.randn(10, 4), columns=["Col1", "Col2", "Col3", "Col4"]
597+
... )
598+
>>> boxplot = df.boxplot(column=["Col1", "Col2", "Col3"]) # doctest: +SKIP
599599
600600
Boxplots of variables distributions grouped by the values of a third
601601
variable can be created using the option ``by``. For instance:
602602
603603
.. plot::
604604
:context: close-figs
605605
606-
>>> df = pd.DataFrame(np.random.randn(10, 2),
607-
... columns=['Col1', 'Col2'])
608-
>>> df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A',
609-
... 'B', 'B', 'B', 'B', 'B'])
610-
>>> boxplot = df.boxplot(by='X')
606+
>>> df = pd.DataFrame(np.random.randn(10, 2), columns=["Col1", "Col2"])
607+
>>> df["X"] = pd.Series(["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"])
608+
>>> boxplot = df.boxplot(by="X")
611609
612610
A list of strings (i.e. ``['X', 'Y']``) can be passed to boxplot
613611
in order to group the data by combination of the variables in the x-axis:
614612
615613
.. plot::
616614
:context: close-figs
617615
618-
>>> df = pd.DataFrame(np.random.randn(10, 3),
619-
... columns=['Col1', 'Col2', 'Col3'])
620-
>>> df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A',
621-
... 'B', 'B', 'B', 'B', 'B'])
622-
>>> df['Y'] = pd.Series(['A', 'B', 'A', 'B', 'A',
623-
... 'B', 'A', 'B', 'A', 'B'])
624-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by=['X', 'Y'])
616+
>>> df = pd.DataFrame(np.random.randn(10, 3), columns=["Col1", "Col2", "Col3"])
617+
>>> df["X"] = pd.Series(["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"])
618+
>>> df["Y"] = pd.Series(["A", "B", "A", "B", "A", "B", "A", "B", "A", "B"])
619+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by=["X", "Y"])
625620
626621
The layout of boxplot can be adjusted giving a tuple to ``layout``:
627622
628623
.. plot::
629624
:context: close-figs
630625
631-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by='X',
632-
... layout=(2, 1))
626+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by="X", layout=(2, 1))
633627
634628
Additional formatting can be done to the boxplot, like suppressing the grid
635629
(``grid=False``), rotating the labels in the x-axis (i.e. ``rot=45``)
@@ -644,23 +638,21 @@ def boxplot(
644638
returned by `boxplot`. When ``return_type='axes'`` is selected,
645639
the matplotlib axes on which the boxplot is drawn are returned:
646640
647-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], return_type='axes')
641+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], return_type="axes")
648642
>>> type(boxplot)
649643
<class 'matplotlib.axes._axes.Axes'>
650644
651645
When grouping with ``by``, a Series mapping columns to ``return_type``
652646
is returned:
653647
654-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by='X',
655-
... return_type='axes')
648+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by="X", return_type="axes")
656649
>>> type(boxplot)
657650
<class 'pandas.Series'>
658651
659652
If ``return_type`` is `None`, a NumPy array of axes with the same shape
660653
as ``layout`` is returned:
661654
662-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by='X',
663-
... return_type=None)
655+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by="X", return_type=None)
664656
>>> type(boxplot)
665657
<class 'numpy.ndarray'>
666658
"""
@@ -791,43 +783,38 @@ def boxplot_frame(
791783
:context: close-figs
792784
793785
>>> np.random.seed(1234)
794-
>>> df = pd.DataFrame(np.random.randn(10, 4),
795-
... columns=['Col1', 'Col2', 'Col3', 'Col4'])
796-
>>> boxplot = df.boxplot(column=['Col1', 'Col2', 'Col3']) # doctest: +SKIP
786+
>>> df = pd.DataFrame(
787+
... np.random.randn(10, 4), columns=["Col1", "Col2", "Col3", "Col4"]
788+
... )
789+
>>> boxplot = df.boxplot(column=["Col1", "Col2", "Col3"]) # doctest: +SKIP
797790
798791
Boxplots of variables distributions grouped by the values of a third
799792
variable can be created using the option ``by``. For instance:
800793
801794
.. plot::
802795
:context: close-figs
803796
804-
>>> df = pd.DataFrame(np.random.randn(10, 2),
805-
... columns=['Col1', 'Col2'])
806-
>>> df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A',
807-
... 'B', 'B', 'B', 'B', 'B'])
808-
>>> boxplot = df.boxplot(by='X')
797+
>>> df = pd.DataFrame(np.random.randn(10, 2), columns=["Col1", "Col2"])
798+
>>> df["X"] = pd.Series(["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"])
799+
>>> boxplot = df.boxplot(by="X")
809800
810801
A list of strings (i.e. ``['X', 'Y']``) can be passed to boxplot
811802
in order to group the data by combination of the variables in the x-axis:
812803
813804
.. plot::
814805
:context: close-figs
815806
816-
>>> df = pd.DataFrame(np.random.randn(10, 3),
817-
... columns=['Col1', 'Col2', 'Col3'])
818-
>>> df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A',
819-
... 'B', 'B', 'B', 'B', 'B'])
820-
>>> df['Y'] = pd.Series(['A', 'B', 'A', 'B', 'A',
821-
... 'B', 'A', 'B', 'A', 'B'])
822-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by=['X', 'Y'])
807+
>>> df = pd.DataFrame(np.random.randn(10, 3), columns=["Col1", "Col2", "Col3"])
808+
>>> df["X"] = pd.Series(["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"])
809+
>>> df["Y"] = pd.Series(["A", "B", "A", "B", "A", "B", "A", "B", "A", "B"])
810+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by=["X", "Y"])
823811
824812
The layout of boxplot can be adjusted giving a tuple to ``layout``:
825813
826814
.. plot::
827815
:context: close-figs
828816
829-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by='X',
830-
... layout=(2, 1))
817+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by="X", layout=(2, 1))
831818
832819
Additional formatting can be done to the boxplot, like suppressing the grid
833820
(``grid=False``), rotating the labels in the x-axis (i.e. ``rot=45``)
@@ -842,23 +829,21 @@ def boxplot_frame(
842829
returned by `boxplot`. When ``return_type='axes'`` is selected,
843830
the matplotlib axes on which the boxplot is drawn are returned:
844831
845-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], return_type='axes')
832+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], return_type="axes")
846833
>>> type(boxplot)
847834
<class 'matplotlib.axes._axes.Axes'>
848835
849836
When grouping with ``by``, a Series mapping columns to ``return_type``
850837
is returned:
851838
852-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by='X',
853-
... return_type='axes')
839+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by="X", return_type="axes")
854840
>>> type(boxplot)
855841
<class 'pandas.Series'>
856842
857843
If ``return_type`` is `None`, a NumPy array of axes with the same shape
858844
as ``layout`` is returned:
859845
860-
>>> boxplot = df.boxplot(column=['Col1', 'Col2'], by='X',
861-
... return_type=None)
846+
>>> boxplot = df.boxplot(column=["Col1", "Col2"], by="X", return_type=None)
862847
>>> type(boxplot)
863848
<class 'numpy.ndarray'>
864849
"""
@@ -1468,10 +1453,13 @@ def line(
14681453
The following example shows the populations for some animals
14691454
over the years.
14701455
1471-
>>> df = pd.DataFrame({
1472-
... 'pig': [20, 18, 489, 675, 1776],
1473-
... 'horse': [4, 25, 281, 600, 1900]
1474-
... }, index=[1990, 1997, 2003, 2009, 2014])
1456+
>>> df = pd.DataFrame(
1457+
... {
1458+
... "pig": [20, 18, 489, 675, 1776],
1459+
... "horse": [4, 25, 281, 600, 1900],
1460+
... },
1461+
... index=[1990, 1997, 2003, 2009, 2014],
1462+
... )
14751463
>>> lines = df.plot.line()
14761464
14771465
.. plot::
@@ -1499,7 +1487,7 @@ def line(
14991487
The following example shows the relationship between both
15001488
populations.
15011489
1502-
>>> lines = df.plot.line(x='pig', y='horse')
1490+
>>> lines = df.plot.line(x="pig", y="horse")
15031491
"""
15041492
if color is not None:
15051493
kwargs["color"] = color
@@ -1570,8 +1558,8 @@ def bar(
15701558
.. plot::
15711559
:context: close-figs
15721560
1573-
>>> df = pd.DataFrame({'lab': ['A', 'B', 'C'], 'val': [10, 30, 20]})
1574-
>>> ax = df.plot.bar(x='lab', y='val', rot=0)
1561+
>>> df = pd.DataFrame({"lab": ["A", "B", "C"], "val": [10, 30, 20]})
1562+
>>> ax = df.plot.bar(x="lab", y="val", rot=0)
15751563
15761564
Plot a whole dataframe to a bar plot. Each column is assigned a
15771565
distinct color, and each row is nested in a group along the
@@ -1582,10 +1570,18 @@ def bar(
15821570
15831571
>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
15841572
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
1585-
>>> index = ['snail', 'pig', 'elephant',
1586-
... 'rabbit', 'giraffe', 'coyote', 'horse']
1587-
>>> df = pd.DataFrame({'speed': speed,
1588-
... 'lifespan': lifespan}, index=index)
1573+
>>> index = [
1574+
... "snail",
1575+
... "pig",
1576+
... "elephant",
1577+
... "rabbit",
1578+
... "giraffe",
1579+
... "coyote",
1580+
... "horse",
1581+
... ]
1582+
>>> df = pd.DataFrame(
1583+
... {"speed": speed, "lifespan": lifespan}, index=index
1584+
... )
15891585
>>> ax = df.plot.bar(rot=0)
15901586
15911587
Plot stacked bar charts for the DataFrame
@@ -1612,8 +1608,9 @@ def bar(
16121608
:context: close-figs
16131609
16141610
>>> axes = df.plot.bar(
1615-
... rot=0, subplots=True,
1616-
... color={"speed": "red", "lifespan": "green"}
1611+
... rot=0,
1612+
... subplots=True,
1613+
... color={"speed": "red", "lifespan": "green"},
16171614
... )
16181615
>>> axes[1].legend(loc=2) # doctest: +SKIP
16191616
@@ -1622,14 +1619,14 @@ def bar(
16221619
.. plot::
16231620
:context: close-figs
16241621
1625-
>>> ax = df.plot.bar(y='speed', rot=0)
1622+
>>> ax = df.plot.bar(y="speed", rot=0)
16261623
16271624
Plot only selected categories for the DataFrame.
16281625
16291626
.. plot::
16301627
:context: close-figs
16311628
1632-
>>> ax = df.plot.bar(x='lifespan', rot=0)
1629+
>>> ax = df.plot.bar(x="lifespan", rot=0)
16331630
"""
16341631
if color is not None:
16351632
kwargs["color"] = color
@@ -1700,8 +1697,8 @@ def barh(
17001697
.. plot::
17011698
:context: close-figs
17021699
1703-
>>> df = pd.DataFrame({'lab': ['A', 'B', 'C'], 'val': [10, 30, 20]})
1704-
>>> ax = df.plot.barh(x='lab', y='val')
1700+
>>> df = pd.DataFrame({"lab": ["A", "B", "C"], "val": [10, 30, 20]})
1701+
>>> ax = df.plot.barh(x="lab", y="val")
17051702
17061703
Plot a whole DataFrame to a horizontal bar plot
17071704
@@ -1710,10 +1707,18 @@ def barh(
17101707
17111708
>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
17121709
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
1713-
>>> index = ['snail', 'pig', 'elephant',
1714-
... 'rabbit', 'giraffe', 'coyote', 'horse']
1715-
>>> df = pd.DataFrame({'speed': speed,
1716-
... 'lifespan': lifespan}, index=index)
1710+
>>> index = [
1711+
... "snail",
1712+
... "pig",
1713+
... "elephant",
1714+
... "rabbit",
1715+
... "giraffe",
1716+
... "coyote",
1717+
... "horse",
1718+
... ]
1719+
>>> df = pd.DataFrame(
1720+
... {"speed": speed, "lifespan": lifespan}, index=index
1721+
... )
17171722
>>> ax = df.plot.barh()
17181723
17191724
Plot stacked barh charts for the DataFrame
@@ -1737,11 +1742,19 @@ def barh(
17371742
17381743
>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
17391744
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
1740-
>>> index = ['snail', 'pig', 'elephant',
1741-
... 'rabbit', 'giraffe', 'coyote', 'horse']
1742-
>>> df = pd.DataFrame({'speed': speed,
1743-
... 'lifespan': lifespan}, index=index)
1744-
>>> ax = df.plot.barh(y='speed')
1745+
>>> index = [
1746+
... "snail",
1747+
... "pig",
1748+
... "elephant",
1749+
... "rabbit",
1750+
... "giraffe",
1751+
... "coyote",
1752+
... "horse",
1753+
... ]
1754+
>>> df = pd.DataFrame(
1755+
... {"speed": speed, "lifespan": lifespan}, index=index
1756+
... )
1757+
>>> ax = df.plot.barh(y="speed")
17451758
17461759
Plot DataFrame versus the desired column
17471760
@@ -1750,11 +1763,19 @@ def barh(
17501763
17511764
>>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
17521765
>>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
1753-
>>> index = ['snail', 'pig', 'elephant',
1754-
... 'rabbit', 'giraffe', 'coyote', 'horse']
1755-
>>> df = pd.DataFrame({'speed': speed,
1756-
... 'lifespan': lifespan}, index=index)
1757-
>>> ax = df.plot.barh(x='lifespan')
1766+
>>> index = [
1767+
... "snail",
1768+
... "pig",
1769+
... "elephant",
1770+
... "rabbit",
1771+
... "giraffe",
1772+
... "coyote",
1773+
... "horse",
1774+
... ]
1775+
>>> df = pd.DataFrame(
1776+
... {"speed": speed, "lifespan": lifespan}, index=index
1777+
... )
1778+
>>> ax = df.plot.barh(x="lifespan")
17581779
"""
17591780
if color is not None:
17601781
kwargs["color"] = color

0 commit comments

Comments
 (0)