Plotting with DataFrame.plot()
DataFrame.plot() is the built-in charting method that turns a Series or DataFrame straight into a Matplotlib figure — line, bar, histogram, scatter, or box — without leaving pandas.
Learn Plotting with DataFrame.plot() in our free Pandas course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…
Part of the free Pandas course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
You will choose chart types with kind= , plot the output of value_counts and groupby , add titles and axis labels, and understand that Matplotlib does the drawing underneath.
Every Series and DataFrame has a .plot() method. With no arguments it draws a line chart using the index as the x-axis. Switch the chart with kind= : "line" , "bar" , "hist" , "scatter" , or "box" . Under the hood, pandas hands everything to Matplotlib .
The most common quick chart is a bar of category counts. Because value_counts() returns a Series, you can chain .plot(kind="bar") right onto it. The same trick works after a groupby aggregation — the grouped result is a Series whose index becomes the bar labels.
Use kind="hist" to see the distribution of one numeric column, kind="scatter" with x= and y= to compare two columns, and kind="box" for spread and outliers. Most chart types accept title= , xlabel= , and ylabel= directly.
Build two charts from one DataFrame and confirm the data behind them.
Lesson complete — your data can speak in pictures!
You can pick a chart with kind= , plot the result of value_counts and groupby , label axes inline, and you know Matplotlib is doing the drawing under .plot() .
🚀 Up next: Method Chaining & .pipe() — write clean, readable multi-step transformations.
Practice quiz
Which library does DataFrame.plot() use under the hood?
- Plotly
- Matplotlib
- Seaborn
- Bokeh
Answer: Matplotlib. pandas plotting is a thin wrapper around Matplotlib.
What chart kind does .plot() draw with no arguments?
- bar
- scatter
- line
- hist
Answer: line. The default kind is 'line', using the index as the x-axis.
Which argument chooses the chart type?
- type=
- chart=
- style=
- kind=
Answer: kind=. Pass kind='line'/'bar'/'hist'/'scatter'/'box' to pick the chart.
What kind draws vertical bars for category totals?
- 'bar'
- 'line'
- 'box'
- 'hist'
Answer: 'bar'. kind='bar' draws vertical bars; great after groupby or value_counts.
Why must a scatter plot specify x and y?
- To set the title
- It compares two specific columns and can't guess them
- To enable color
- Scatter is always sorted
Answer: It compares two specific columns and can't guess them. A scatter needs both axes named because it relates two chosen columns.
What object does .plot() return?
- A DataFrame
- A Matplotlib Axes you can keep customising
- None
- A Series
Answer: A Matplotlib Axes you can keep customising. .plot() returns a Matplotlib Axes, so you can tweak labels, limits, and legend afterwards.
How do you chart category frequencies as bars in one line?
- df.plot(kind='hist')
- df.sort_values().plot()
- df.describe().plot()
- city
Answer: city. value_counts() returns a Series, so .plot(kind='bar') charts it directly.
Which kind shows the distribution of a single numeric column?
- 'hist'
- 'scatter'
- 'line'
- 'bar'
Answer: 'hist'. kind='hist' bins one column to reveal its distribution.
By default, value_counts() sorts bars how?
- Alphabetically
- By frequency (tallest first)
- Randomly
- By index
Answer: By frequency (tallest first). value_counts sorts by count, so add .sort_index() for label order.
Which kind is best for spread and outliers?
- 'line'
- 'scatter'
- 'box'
- 'bar'
Answer: 'box'. kind='box' shows median, quartiles, and outliers.