0% found this document useful (0 votes)
0 views

Matplotlib Notes Part1 With Code

The document provides a comprehensive guide on creating various types of plots using Matplotlib, including basic plots, labeled plots, styled plots, and legends. It covers additional features such as grid lines, subplots, figure size adjustments, bar plots, histograms, scatter plots, pie charts, and saving plots. Each section includes example code snippets to illustrate the concepts.

Uploaded by

tupacmoosewala
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)
0 views

Matplotlib Notes Part1 With Code

The document provides a comprehensive guide on creating various types of plots using Matplotlib, including basic plots, labeled plots, styled plots, and legends. It covers additional features such as grid lines, subplots, figure size adjustments, bar plots, histograms, scatter plots, pie charts, and saving plots. Each section includes example code snippets to illustrate the concepts.

Uploaded by

tupacmoosewala
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/ 12

1.

Basic Plot
1.0

0.5

0.0

0.5

1.0
0 2 4 6 8 10
plt.plot(x, y)
plt.show()
2. Labels and Title
1.0

0.5

0.0

0.5

1.0
0 2 4 6 8 10
Time
plt.plot(x, y)
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.title('Sine Wave')
3. Styling the Plot
1.0

0.5

0.0

0.5

1.0
0 2 4 6 8 10
plt.plot(x, y, color='r', linestyle='--', marker='o')
4. Legends
1.0 sin(x)
cos(x)
0.5

0.0

0.5

1.0
0 2 4 6 8 10
plt.plot(x, y1, label='sin(x)')
plt.plot(x, y2, label='cos(x)')
plt.legend()
5. Grid
1.0

0.5

0.0

0.5

1.0
0 2 4 6 8 10
plt.plot(x, y)
plt.grid(True)
6. Subplots
1.0

0.5

0.0

0.5

1.0
0 1 2 3 4 5
fig, axs = plt.subplots(2, 1)
axs[0].plot(x, y1)
axs[1].plot(x, y2)
7. Figure Size
1.0

0.5

0.0

0.5

1.0
0 2 4 6 8 10
plt.figure(figsize=(8, 4))
plt.plot(x, y)
8. Bar Plot
20

15

10

0 A B C
plt.bar(categories, values)
9. Histogram

15

10

0 2 1 0 1 2
plt.hist(data, bins=10)
10. Scatter Plot
1.0

0.5

0.0

0.5

1.0
0 2 4 6 8 10
plt.scatter(x, y)
11. Pie Chart
A
B 22.2%
44.4%

33.3%
C

plt.pie(values, labels=categories, autopct='%1.1f%%')


12. Save Plot
1.0

0.5

0.0

0.5

1.0
0 2 4 6 8 10
plt.savefig('filename.png')

You might also like