Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.plot#

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

Make plots of Series or DataFrame.

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

Parameters:
dataSeries or DataFrame

The object for which the method is called.

xlabel or position, default None

Only used if data is a DataFrame.

ylabel, position or list of label, positions, default None

Allows plotting of one column versus another. Only used if data is aDataFrame.

kindstr

The kind of plot to produce:

  • ‘line’ : line plot (default)

  • ‘bar’ : vertical bar plot

  • ‘barh’ : horizontal bar plot

  • ‘hist’ : histogram

  • ‘box’ : boxplot

  • ‘kde’ : Kernel Density Estimation plot

  • ‘density’ : same as ‘kde’

  • ‘area’ : area plot

  • ‘pie’ : pie plot

  • ‘scatter’ : scatter plot (DataFrame only)

  • ‘hexbin’ : hexbin plot (DataFrame only)

axmatplotlib axes object, default None

An axes of the current figure.

subplotsbool or sequence of iterables, default False

Whether to group columns into subplots:

  • False : No subplots will be used

  • True : Make separate subplots for each column.

  • sequence of iterables of column labels: Create a subplot for eachgroup of columns. For example[(‘a’, ‘c’), (‘b’, ‘d’)] willcreate 2 subplots: one with columns ‘a’ and ‘c’, and onewith columns ‘b’ and ‘d’. Remaining columns that aren’t specifiedwill be plotted in additional subplots (one per column).

    Added in version 1.5.0.

sharexbool, default True if ax is None else False

In casesubplots=True, share x axis and set some x axis labelsto invisible; defaults to True if ax is None otherwise False ifan ax is passed in; Be aware, that passing in both an ax andsharex=True will alter all x axis labels for all axis in a figure.

shareybool, default False

In casesubplots=True, share y axis and set some y axis labels to invisible.

layouttuple, optional

(rows, columns) for the layout of subplots.

figsizea tuple (width, height) in inches

Size of a figure object.

use_indexbool, default True

Use index as ticks for x axis.

titlestr or list

Title to use for the plot. If a string is passed, print the stringat the top of the figure. If a list is passed andsubplots isTrue, print each item in the list above the corresponding subplot.

gridbool, default None (matlab style default)

Axis grid lines.

legendbool or {‘reverse’}

Place legend on axis subplots.

stylelist or dict

The matplotlib line style per column.

logxbool or ‘sym’, default False

Use log scaling or symlog scaling on x axis.

logybool or ‘sym’ default False

Use log scaling or symlog scaling on y axis.

loglogbool or ‘sym’, default False

Use log scaling or symlog scaling on both x and y axes.

xtickssequence

Values to use for the xticks.

ytickssequence

Values to use for the yticks.

xlim2-tuple/list

Set the x limits of the current axes.

ylim2-tuple/list

Set the y limits of the current axes.

xlabellabel, optional

Name to use for the xlabel on x-axis. Default uses index name as xlabel, or thex-column name for planar plots.

Changed in version 2.0.0:Now applicable to histograms.

ylabellabel, optional

Name to use for the ylabel on y-axis. Default will show no ylabel, or they-column name for planar plots.

Changed in version 2.0.0:Now applicable to histograms.

rotfloat, default None

Rotation for ticks (xticks for vertical, yticks for horizontalplots).

fontsizefloat, default None

Font size for xticks and yticks.

colormapstr or matplotlib colormap object, default None

Colormap to select colors from. If string, load colormap with thatname from matplotlib.

colorbarbool, optional

If True, plot colorbar (only relevant for ‘scatter’ and ‘hexbin’plots).

positionfloat

Specify relative alignments for bar plot layout.From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5(center).

tablebool, Series or DataFrame, default False

If True, draw a table using the data in the DataFrame and the datawill be transposed to meet matplotlib’s default layout.If a Series or DataFrame is passed, use passed data to draw atable.

yerrDataFrame, Series, array-like, dict and str

SeePlotting with Error Bars fordetail.

xerrDataFrame, Series, array-like, dict and str

Equivalent to yerr.

stackedbool, default False in line and bar plots, and True in area plot

If True, create stacked plot.

secondary_ybool or sequence, default False

Whether to plot on the secondary y-axis if a list/tuple, whichcolumns to plot on secondary y-axis.

mark_rightbool, default True

When using a secondary_y axis, automatically mark the columnlabels with “(right)” in the legend.

include_boolbool, default is False

If True, boolean values can be plotted.

backendstr, default None

Backend to use instead of the backend specified in the optionplotting.backend. For instance, ‘matplotlib’. Alternatively, tospecify theplotting.backend for the whole session, setpd.options.plotting.backend.

**kwargs

Options to pass to matplotlib plotting method.

Returns:
matplotlib.axes.Axes or numpy.ndarray of them

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

Notes

  • See matplotlib documentation online for more on this subject

  • Ifkind = ‘bar’ or ‘barh’, you can specify relative alignmentsfor bar plot layout byposition keyword.From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5(center)

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(lambdax: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

[8]ページ先頭

©2009-2025 Movatter.jp