pandas.DataFrame.plot — pandas 3.0.0.dev0+2097.gcdc5b7418e documentation (original) (raw)

DataFrame.plot(*args, **kwargs)[source]#

Make plots of Series or DataFrame.

Uses the backend specified by the option plotting.backend. By default, matplotlib is used.

Parameters:

dataSeries or DataFrame

The object for which the method is called.

Attributes

Returns:

matplotlib.axes.Axes or numpy.ndarray of them

If the backend is not the default matplotlib one, the return value will be the object returned by the backend.

Notes

Examples

For Series:

ser = pd.Series([1, 2, 3, 3]) plot = ser.plot(kind="hist", title="My plot")

../../_images/pandas-DataFrame-plot-1.png

For DataFrame:

df = pd.DataFrame( ... { ... "length": [1.5, 0.5, 1.2, 0.9, 3], ... "width": [0.7, 0.2, 0.15, 0.2, 1.1], ... }, ... index=["pig", "rabbit", "duck", "chicken", "horse"], ... ) plot = df.plot(title="DataFrame Plot")

../../_images/pandas-DataFrame-plot-2.png

For SeriesGroupBy:

lst = [-1, -2, -3, 1, 2, 3] ser = pd.Series([1, 2, 2, 4, 6, 6], index=lst) plot = ser.groupby(lambda x: x > 0).plot(title="SeriesGroupBy Plot")

../../_images/pandas-DataFrame-plot-3.png

For DataFrameGroupBy:

df = pd.DataFrame({"col1": [1, 2, 3, 4], "col2": ["A", "B", "A", "B"]}) plot = df.groupby("col2").plot(kind="bar", title="DataFrameGroupBy Plot")

../../_images/pandas-DataFrame-plot-4_00.png

../../_images/pandas-DataFrame-plot-4_01.png