Data ScienceIntermediate

Data Visualization with Matplotlib

Learn data visualization in Python with Matplotlib! A fun guide to creating line plots, scatter plots, and bar charts the recommended object-oriented way.

Try it yourself

Run this code directly in your browser. Click "Open in full editor" to experiment further.

Loading...

Click Run to see output

Or press Ctrl + Enter

How it works

Ready to make some beautiful charts and graphs? Say hello to Matplotlib, Python's legendary data visualization tool!

The Object-Oriented Approach

You might see some older tutorials use simple plt.plot() commands, but the pro developer way is called the Object-Oriented API (like we did in the code!).

fig, ax = plt.subplots()
  • fig (Figure): The actual window or piece of paper you're drawing on.
  • ax (Axes): The chart area itself. You can have multiple charts (ax1, ax2) inside one single figure!
  • Types of Plots

    1. Line Plots (`ax.plot`): Amazing for showing smooth trends over time (like stock prices moving up and down, or smooth math waves).

    2. Scatter Plots (`ax.scatter`): The absolute best choice when you have a bunch of individual data dots and you want to see if there's a pattern, cluster, or relationship between them.

    3. Bar Charts (`ax.bar`): Perfect for comparing totally different categories against each other (like test scores between classes or car sales by month).

    Whenever you are ready, go ahead and run the code! Depending on where you run it (like Jupyter Notebooks or a web playground), the beautiful image charts will render right before your eyes!

    Related examples

    Keywords: python matplotlib tutorial, matplotlib data visualization, python line plot, python scatter plot, matplotlib pyplot python