0% found this document useful (0 votes)
52 views2 pages

Matplotlib Notes

Matplotlib is a widely-used Python library for data visualization, enabling the creation of various chart types such as line, bar, pie, scatter, and histogram. Key functions include plt.plot for line charts and plt.bar for bar charts, with customization options for markers, colors, and line styles. The library is particularly effective for 2D visualizations and works seamlessly with NumPy and Pandas for data manipulation.

Uploaded by

shivamshukla9172
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views2 pages

Matplotlib Notes

Matplotlib is a widely-used Python library for data visualization, enabling the creation of various chart types such as line, bar, pie, scatter, and histogram. Key functions include plt.plot for line charts and plt.bar for bar charts, with customization options for markers, colors, and line styles. The library is particularly effective for 2D visualizations and works seamlessly with NumPy and Pandas for data manipulation.

Uploaded by

shivamshukla9172
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

📊 Matplotlib – Brief Notes

1. Introduction
• Matplotlib is a popular Python library used for data visualization.

• It helps to create different types of charts and graphs like line charts, bar charts,
histograms, scatter plots, and pie charts.

• Module used: matplotlib.pyplot (commonly imported as plt).

import matplotlib.pyplot as plt

2. Basic Plot
x = [1, 2, 3, 4]
y = [2, 4, 6, 8]

plt.plot(x, y) # creates a line chart


plt.show()

3. Common Functions
• plt.plot(x, y) → Line chart

• plt.bar(x, y) → Bar chart

• plt.pie(values) → Pie chart

• plt.scatter(x, y) → Scatter plot

• plt.hist(data) → Histogram

• plt.show() → Displays the graph

4. Adding Labels and Title


plt.plot(x, y)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Simple Line Graph")
plt.show()
5. Customization
• Markers & Colors in line chart:

plt.plot(x, y, marker='o', color='red', linestyle='--')


• marker='o' → circle points

• color='red' → red line

• linestyle='--' → dashed line

6. Multiple Lines
x = [1,2,3,4]
y1 = [1,4,9,16]
y2 = [2,4,6,8]

plt.plot(x, y1, label="Squares")


plt.plot(x, y2, label="Doubles")
plt.legend()
plt.show()

7. Pie Chart Example


sizes = [20, 30, 25, 25]
labels = ['A', 'B', 'C', 'D']
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.show()

8. Key Points
• Matplotlib is mainly used for 2D visualizations.

• Helps in understanding data patterns and trends.

• Works well with NumPy and Pandas for data handling.

✨ Shortcut for remembering: L-B-P-S-H (Line, Bar, Pie, Scatter, Histogram) → 5 main chart
types.

You might also like