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.
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
NumPy Array Operations in Python
Learn NumPy basics in Python! A fun and easy guide to super-fast arrays, matrices, and data science math without using slow for-loops.
Data Analysis with Pandas in Python
Learn Pandas for data analysis in Python! A beginner-friendly guide to DataFrames, filtering data, grouping, and handling messy missing data just like Excel.