Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 39 ยท Exploration and Visualization

Visualizing Data

Choose the right plot for exploring data: histograms, box plots, scatter plots, bar charts, heatmaps and pair plots, with matplotlib code that runs in your browser.

Numbers summarize; pictures reveal. Two data sets can share the same mean, spread and correlation and still look completely different. A plot shows clusters, gaps, outliers, curves and mistakes that a table of statistics will never show. Data visualization is therefore a core part of exploration, and later a way to present mined results to people who do not read code.

This lesson uses matplotlib and pandas. Every figure appears below the code when you press Run. For a deeper tour see the Matplotlib tutorial.

Match the plot to the question

One variable

Histogram Shape of a numeric column.
Box plot Median, spread, outliers.
Bar chart Counts per category.
1 / 2

Histogram: the shape of one attribute

A histogram splits the range into bins and counts values per bin. Watch for skew, several peaks (maybe mixed groups), and gaps.

Python Histogram of a skewed and a bimodal attribute

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The right histogram suggests two populations. A clustering algorithm may find them; a single mean (45) would describe nobody.

Box plot: compare groups

A box plot draws the median, the box from Q1 to Q3, whiskers at roughly 1.5 IQR, and dots for points beyond. It is excellent for comparing groups side by side.

Python Box plot per group

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Bar chart for categories

Python Counts per category

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Sort bars by size and start the axis at zero: bars encode length, so a cut axis lies.

Scatter plot: two numeric attributes

Scatter plots show correlation, curves, clusters and outliers. Color points by a category to add a third variable.

Python Scatter plot with a hidden group structure

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When you have thousands of points, use small markers with alpha, or a 2D histogram (plt.hist2d) to avoid over-plotting.

Heatmap and pair plot: many attributes at once

A correlation heatmap shows all pairwise correlations as colors. A scatter matrix (pair plot) shows every pair as a small scatter plot.

Python Correlation heatmap and scatter matrix

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Time series line chart

Python Trend with a rolling mean

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Principles of honest charts

  • Label axes and units; give the chart a title that states the finding.
  • Start bar charts at zero. Lines and scatter plots may zoom.
  • Use color for meaning, not decoration, and avoid red-green pairs only.
  • Do not use 3D or pie charts when a bar chart reads more accurately.
  • Plot the data, not only the summary: show the distribution, not just the mean.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which plot best shows the shape of one numeric attribute?

    A histogram shows skew, peaks and gaps of a single numeric column.
  2. 2. A histogram with two clear peaks suggests:

    Two peaks often mean two groups, which clustering might separate.
  3. 3. In a box plot, dots beyond the whiskers are:

    Points beyond about 1.5 IQR from the box are drawn individually as possible outliers.
  4. 4. Why should a bar chart axis start at zero?

    A truncated bar axis visually misleads about relative sizes.

Summary

  • Pick the plot by question: histogram or box plot for one numeric column, bar chart for categories, scatter for two numbers, heatmap or pair plot for many, line chart for time.
  • Plots reveal skew, groups, outliers and errors that summary numbers hide.
  • Handle over-plotting with transparency or 2D histograms.
  • Keep charts honest: labels, zero baselines for bars, meaningful color.

Next: Correlation and Relationships