Plotting a pandas DataFrame turns selected columns into a quick chart that can be reviewed before a report, notebook, or dashboard gets more styling. DataFrame.plot() uses the Matplotlib plotting backend by default, so the same call can create a chart and hand the figure to Matplotlib for saving.

A small sales DataFrame keeps the column selection visible because one column supplies the x-axis and two numeric columns become grouped bars. The same pattern works after a CSV, SQL query, Parquet file, or pivot table has already produced the DataFrame.

Saving with savefig() keeps the result usable outside an interactive notebook. A nonzero PNG file and an Axes return value show that pandas created the chart and Matplotlib wrote it to disk.

Steps to plot a pandas DataFrame:

  1. Save the plotting script as plot_dataframe.py.
    plot_dataframe.py
    from pathlib import Path
     
    import matplotlib
     
    matplotlib.use("Agg")
     
    import matplotlib.pyplot as plt
    import pandas as pd
     
    sales = pd.DataFrame(
        {
            "quarter": ["2026 Q1", "2026 Q2", "2026 Q3", "2026 Q4"],
            "hardware": [18000, 21500, 23100, 26000],
            "software": [9500, 12000, 14800, 17100],
        }
    )
     
    ax = sales.plot(
        x="quarter",
        y=["hardware", "software"],
        kind="bar",
        figsize=(7, 4),
        rot=0,
        title="Quarterly revenue",
    )
    ax.set_xlabel("Quarter")
    ax.set_ylabel("USD")
    ax.legend(title="Segment")
     
    figure = ax.get_figure()
    figure.tight_layout()
     
    output = Path("sales-by-quarter.png")
    figure.savefig(output, dpi=150)
    plt.close(figure)
     
    print(sales.to_string(index=False))
    print(f"axes: {type(ax).__name__}")
    print(f"title: {ax.get_title()}")
    print(f"saved: {output}")
    print(f"bytes: {output.stat().st_size}")

    matplotlib.use(“Agg”) selects a file-rendering backend so the script can save a PNG from a terminal, CI job, or server session without opening a desktop window. Run it in the same environment that imports pandas and Matplotlib.
    Related: How to install pandas with pip

  2. Run the script.
    $ python3 plot_dataframe.py
    quarter  hardware  software
    2026 Q1     18000      9500
    2026 Q2     21500     12000
    2026 Q3     23100     14800
    2026 Q4     26000     17100
    axes: Axes
    title: Quarterly revenue
    saved: sales-by-quarter.png
    bytes: 32781

    The exact byte count can change with Matplotlib, font, or backend versions. A positive byte count and the expected filename confirm that the PNG was written.

  3. Open sales-by-quarter.png in an image viewer, notebook output cell, or report preview.

    The chart should show grouped bars for hardware and software across the four quarter labels.

  4. Remove the sample script and PNG when they were created only for testing.
    $ rm plot_dataframe.py sales-by-quarter.png