# Pandas Plotting: A Guide to df.plot() in Python

> Plot a pandas DataFrame with df.plot(kind="line"), "bar", "hist", "box", "area", "scatter" and more. Which kind to use, how df.plot works with Matplotlib, and fixes for common errors.

Source: https://www.pythoncharts.com/pandas/pandas-plotting/ | Published: 2026-12-05 | Author: Alex Scott | Category: Pandas | Tags: pandas, guide, df.plot, line plot, bar chart, histogram

To plot a pandas DataFrame, call `df.plot()`. It draws one line per numeric column against the index, using Matplotlib. Pick another chart with `kind=` (`df.plot(kind="bar")`) or the matching method (`df.plot.bar()`). It returns a Matplotlib `Axes`, so everything you know about Matplotlib still works on the result. This page links the pandas plotting tutorials on this site, grouped by task, and the examples are written for pandas 3.0.

![Grid of nine pandas charts: multi-column line chart, stacked bars, histograms and box plots, a groupby bar chart, a rolling average, a scatter matrix, a secondary y-axis, error bars, and a styled table](https://www.pythoncharts.com/pandas/pandas-plotting/images/pandas-plotting-montage.png)

## Quick Example

```python
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

rng = np.random.default_rng(31)
months = pd.period_range("2025-01", periods=12, freq="M")
season = np.cos(2 * np.pi * np.arange(12) / 12)
sales = pd.DataFrame({
    "Latte": 1800 + 300 * season + rng.normal(0, 60, 12),
    "Cold brew": 900 - 550 * season + rng.normal(0, 60, 12),
    "Tea": 700 + 150 * season + rng.normal(0, 40, 12),
}, index=months).round()

ax = sales.plot(figsize=(8, 4.5), marker="o", ylim=(0, 2600),
                title="Cups sold per month", ylabel="Cups")
ax.legend(loc="upper left", ncols=3)
plt.show()
```

![Pandas line chart of monthly cups sold in 2025: latte is highest in winter at about 2,100, cold brew peaks in July at about 1,430, and tea stays between about 530 and 840](https://www.pythoncharts.com/pandas/pandas-plotting/images/pandas-plotting-quick-example.png)

Each column becomes a line and the index becomes the x-axis. The index here is a `PeriodIndex` of months, which works for every kind; see the errors table below for a bar chart bug with dates in pandas 3.0.0 to 3.0.5. `figsize`, `ylim`, `title`, and `ylabel` go straight to `df.plot()`; for anything else, use the returned `ax`.

## Which `df.plot` kind should I use?

`df.plot(kind=...)` and `df.plot.<kind>()` are the same thing. These six panels plot the same `sales` DataFrame. The bar panel uses month names as a text index, because bar charts label every row of the index, and how pandas labels dates on bars has changed between 3.0 and 3.1:

```python
kinds = ["line", "bar", "area", "hist", "box", "kde"]

by_month = sales.set_axis(sales.index.strftime("%b"))  # text labels for the bars

fig, axs = plt.subplots(2, 3, figsize=(13, 7), layout="constrained")
for ax, kind in zip(axs.flat, kinds):
    data = by_month if kind == "bar" else sales
    options = {"alpha": 0.6} if kind == "hist" else {}
    data.plot(kind=kind, ax=ax, legend=False, rot=0, **options)
    ax.set_title(f'kind="{kind}"', family="monospace")
    ax.set_xlabel("")
fig.legend(*axs[0, 0].get_legend_handles_labels(), loc="outside upper center", ncols=3)
plt.show()
```

![Six charts of the same monthly drink sales drawn with df.plot kinds line, bar, area, hist, box, and kde](https://www.pythoncharts.com/pandas/pandas-plotting/images/pandas-plotting-kinds.png)

| To show | Call | Tutorial |
|---|---|---|
| Several columns over time | `df.plot()` | [Multiple columns on one line chart](https://www.pythoncharts.com/pandas/multiple-columns-line-chart-pandas/) |
| Values by category | `df.plot.bar()`, `df.plot.barh()` | [Stacked vs unstacked bars](https://www.pythoncharts.com/pandas/pandas-stacked-vs-unstacked-bar-charts/) |
| Group totals or a pivot table | `df.groupby(...).sum().plot.bar()` | [Plot groupby and pivot table results](https://www.pythoncharts.com/pandas/pandas-plot-groupby/) |
| Distributions | `df.plot.hist()`, `df.plot.box()`, `df.hist()`, `df.boxplot()` | [Histograms and box plots](https://www.pythoncharts.com/pandas/pandas-histogram-boxplot/) |
| Smoothed distributions | `df.plot.kde()` (needs SciPy) | [Seaborn kdeplot](https://www.pythoncharts.com/seaborn/seaborn-kdeplot-density/) has more control |
| Parts of a total over time | `df.plot.area()` | [Matplotlib area charts](https://www.pythoncharts.com/matplotlib/matplotlib-area-chart/) |
| Two columns against each other | `df.plot.scatter(x="a", y="b")` | [Matplotlib scatter plots](https://www.pythoncharts.com/matplotlib/matplotlib-scatterplot/) |
| Every pair of columns | `pd.plotting.scatter_matrix(df)` | [scatter_matrix](https://www.pythoncharts.com/pandas/pandas-scatter-matrix/) |
| A trend under noisy data | `df.rolling(7).mean().plot()` | [Rolling averages](https://www.pythoncharts.com/pandas/pandas-rolling-average/) |
| Dense scatter data | `df.plot.hexbin(x="a", y="b")` | [Hexbin plots](https://www.pythoncharts.com/matplotlib/matplotlib-hexbin-2d-histogram/) |
| Shares of one total | `df.plot.pie(y="col")` | [Matplotlib pie charts](https://www.pythoncharts.com/matplotlib/pie-chart-matplotlib/) |

To choose by how the chart looks, browse the [Python Chart Gallery](https://www.pythoncharts.com/chart-gallery/).

## Customize pandas plots

| You want to | Tutorial |
|---|---|
| Change the figure size | [figsize with df.plot](https://www.pythoncharts.com/pandas/change-figure-size-df-plot/) |
| Put a second column on its own y-axis | [Secondary y-axis](https://www.pythoncharts.com/pandas/secondary-y-axis-pandas/) |
| Add error bars | [Error bars on DataFrame plots](https://www.pythoncharts.com/pandas/pandas-error-bars/) |
| Resample to weeks or months before plotting | [Time series with a custom frequency](https://www.pythoncharts.com/pandas/pandas-time-series-custom-frequency/) |
| Print values on the bars | [Matplotlib bar_label](https://www.pythoncharts.com/matplotlib/matplotlib-bar-label/) works on pandas bars through `ax.containers` |
| Format dates on the x-axis | [Matplotlib date formatting](https://www.pythoncharts.com/matplotlib/matplotlib-custom-date-formatting/) |

## How does `df.plot` work with Matplotlib?

pandas builds the chart with Matplotlib and gives you back the `Axes`:

- `ax = df.plot(...)` returns the axes, so `ax.set_title()`, `ax.legend()`, `ax.bar_label()`, and the rest of Matplotlib work on it.
- `df.plot(ax=ax)` draws onto axes you already made, for example one panel of `plt.subplots(2, 2)`.
- `df.plot(subplots=True)` gives each column its own panel and returns a NumPy array of axes.
- Keyword arguments pandas doesn't use (`color`, `linewidth`, `marker`, `alpha`) are passed on to Matplotlib.

The [Matplotlib tutorial](https://www.pythoncharts.com/matplotlib/matplotlib-tutorial/) is the reference for anything you change after plotting.

## Interactive charts from a DataFrame

`df.plot` makes static images. For hover, zoom, and pan, switch the backend or use a library that reads DataFrames directly:

- `pd.options.plotting.backend = "plotly"` makes `df.plot()` return a Plotly figure. See [the Plotly plotting backend](https://www.pythoncharts.com/pandas/pandas-plotly-backend/).
- `import hvplot.pandas` adds `df.hvplot()`, which takes nearly the same arguments as `df.plot()`. See [hvPlot](https://www.pythoncharts.com/python/hvplot-pandas-interactive-plots/).
- Polars DataFrames have their own `df.plot`, built on Altair. See [plotting a Polars DataFrame](https://www.pythoncharts.com/python/polars-plotting/).

## Format a DataFrame as a table

Sometimes the right output is a well-formatted table rather than a chart:

- [`df.style`](https://www.pythoncharts.com/pandas/pandas-style-dataframe/) adds number formats, color gradients, and highlights in Jupyter and HTML.
- [Great Tables](https://www.pythoncharts.com/python/great-tables-python/) makes publication-quality tables with titles, spanners, and footnotes.

## Should I use pandas, Matplotlib, Seaborn, or Plotly?

| Choose | When |
|---|---|
| `df.plot()` | A quick look at a DataFrame that's already shaped the way you want to plot it (one column per series) |
| [Matplotlib](https://www.pythoncharts.com/matplotlib/matplotlib-tutorial/) | You need full control of a static chart |
| [Seaborn](https://www.pythoncharts.com/seaborn/seaborn-tutorial/) | Your data is in long format (one row per observation) and you want grouping, statistics, and color by category handled for you |
| [Plotly](https://www.pythoncharts.com/plotly/plotly-tutorial/) | Readers need to hover, zoom, or filter |

The main difference between pandas and Seaborn is data shape. `df.plot()` wants wide data: one column per line or bar group. Seaborn wants long data plus `hue="column"`. `df.melt()` turns wide into long, and `df.pivot()` goes the other way.

## Common pandas plotting errors

| Problem | Cause | Fix |
|---|---|---|
| `TypeError: no numeric data to plot` | The columns are strings or `object` dtype | Convert with `pd.to_numeric(df["col"])` or `df.astype(float)` |
| `ValueError: scatter requires an x and y column` | `kind="scatter"` without `x=` and `y=` | `df.plot.scatter(x="a", y="b")` |
| `ValueError: pie requires either y column or 'subplots=True'` | A pie on a DataFrame with several columns | `df.plot.pie(y="col")` |
| The plot doesn't appear | Not in a notebook, or no `plt.show()` | Call `plt.show()`; see [plot not showing](https://www.pythoncharts.com/matplotlib/matplotlib-plot-not-showing/) |
| `figsize` is ignored | It was set on a different figure than the one pandas drew on | Pass `figsize=` to `df.plot()`, or make the figure first and pass `ax=` |
| Bars are in the wrong order | Bars follow the index order | Sort first: `df.sort_values("col").plot.barh()` |
| `ValueError: Must supply freq for datetime value` or `<MonthBegin> is not supported as period frequency` from `df.plot.bar()` | A bug in pandas 3.0.0 to 3.0.5 with dates on the x-axis of bar charts ([pandas issue #67755](https://github.com/pandas-dev/pandas/issues/67755)) | Upgrade to pandas 3.0.6 or later. On an older 3.0 release, label the bars as text: `df.set_axis(df.index.strftime("%b %Y")).plot.bar()` |

## Similar Topics

- [Matplotlib Tutorial: A Guide from First Plot to Polished Chart](https://www.pythoncharts.com/matplotlib/matplotlib-tutorial/)
- [Seaborn Tutorial: A Guide to Statistical Charts in Python](https://www.pythoncharts.com/seaborn/seaborn-tutorial/)
- [hvPlot: Interactive Plots From pandas in One Line](https://www.pythoncharts.com/python/hvplot-pandas-interactive-plots/)
