Matplotlib
Source: 10-Data Analysis With Python/10.5-matplotlib.ipynb
Start here — no coding background needed
What you will learn
Draw charts from numbers — lines, bars, scatter.
In simple words
Charts help you see trends faster than reading hundreds of numbers.
Spreadsheet-style work with code — for data jobs. Beginners: read concepts, run small examples.
Easy example — run this first. Change values and press Run again.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Reference notes (from full bootcamp)
Optional — deeper detail for when you are ready
Data Visualization With Matplotlib
Matplotlib is a powerful plotting library for Python that enables the creation of static, animated, and interactive visualizations. It is widely used for data visualization in data science and analytics. In this lesson, we will cover the basics of Matplotlib, including creating various types of plots and customizing them.
!pip install matplotlib
Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Runs in your browser via Pyodide — no server. First run may take a few seconds.
x=[1,2,3,4,5]
y=[1,4,9,16,25]
##create a line plot
plt.plot(x,y)
plt.xlabel('X axis')
plt.ylabel('Y Axis')
plt.title("Basic Line Plot")
plt.show()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): Text(0.5, 1.0, 'Plot 4')
Runs in your browser via Pyodide — no server. First run may take a few seconds.
###Bar Plor
categories=['A','B','C','D','E']
values=[5,7,3,8,6]
##create a bar plot
plt.bar(categories,values,color='purple')
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Plot')
plt.show()Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Histograms
Histograms are used to represent the distribution of a dataset. They divide the data into bins and count the number of data points in each bin.
Expected (from notebook): (array([1., 2., 3., 4., 5.]), array([1. , 1.8, 2.6, 3.4, 4.2, 5. ]), <BarContainer object of 5 artists>)
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): <matplotlib.collections.PathCollection at 0x25699a6b080>
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): ([<matplotlib.patches.Wedge at 0x2569ea3ca10>, <matplotlib.patches.Wedge at 0x2569ea3c8f0>, <matplotlib.patches.Wedge at 0x2569ea3d4f0>, <matplotlib.patches.Wedge at 0x2569ea3dbb0>], [Text(0.764120788592483, 1.051722121304293, 'A'), Text(-0.8899187482945419, 0.6465637025335369, 'B'), Text(-0.3399185762739153, -1.046162206115244, 'C'), Text(1.0461622140716127, -0.3399185517867209, 'D')], [Text(0.47022817759537416, 0.6472136131103341, '30.0%'), Text(-0.4854102263424773, 0.3526711104728383, '20.0%'), Text(-0.1854101325130447, -0.5706339306083149, '40.0%'), Text(0.5706339349481523, -0.18541011915639322, '10.0%')])
Runs in your browser via Pyodide — no server. First run may take a few seconds.
## Sales Data Visualization
import pandas as pd
sales_data_df=pd.read_csv('sales_data.csv')
sales_data_df.head(5)Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).
Expected (from notebook): <class 'pandas.core.frame.DataFrame'> RangeIndex: 240 entries, 0 to 239 Data columns (total 9 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Transaction ID 240 non-null int64 1 Date 240 non-null object 2 Product Category 240 non-null object 3 Product Name 240 non-null object 4 Units Sold 240 non-null int64 5 Unit Price 240 non-null float64 6 Total Revenue 240 non-null float64 7 Region 240 non-null object 8 Payment Method 240 non-null object dtypes: float64(2), int64(2), object(5) memory usage: 17.0+ KB
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): Product Category Beauty Products 2621.90 Books 1861.93 Clothing 8128.93 Electronics 34982.41 Home Appliances 18646.16 Sports 14326.52 Name: Total Revenue, dtype: float64
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): <Axes: xlabel='Product Category'>
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): [<matplotlib.lines.Line2D at 0x2569e9b46e0>]
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Practice test — try yourself
Write code, press Check. Wrong answer shows the correct code to copy & run.
You learned "Matplotlib". Use print() to show: Done: Matplotlib
Hint: Use one print() with the exact text.