0% found this document useful (0 votes)
2 views18 pages

22) - Matplotlib

The document provides a comprehensive guide to creating various types of plots using Matplotlib, including bar charts, histograms, line plots, and pie charts. It includes code snippets for generating these plots along with explanations of parameters and customization options. The document serves as a practical reference for users looking to visualize data effectively with Matplotlib.

Uploaded by

mohit
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)
2 views18 pages

22) - Matplotlib

The document provides a comprehensive guide to creating various types of plots using Matplotlib, including bar charts, histograms, line plots, and pie charts. It includes code snippets for generating these plots along with explanations of parameters and customization options. The document serves as a practical reference for users looking to visualize data effectively with Matplotlib.

Uploaded by

mohit
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

Matplotlib

May 3, 2021

1 Matplotlib
[Link]

1.1 Bar Chart


[16]: import [Link] as plt

[17]: x = [i for i in range(1,11)]

y = [i**2 for i in range(1,11)]

# more parameters for bar() -


# [Link]

[Link](x,y)

[Link]('Number sqr')
[Link]('Numbers')
[Link]('Squares')

[Link]()

1
[18]: x = [i for i in range(1,11)]

y1 = [i**2 for i in range(1,11)]


y2 = [i**3 for i in range(1,11)]

[Link](x,y1, color='#123456', label='Y1')


[Link](x,y2, color='#000456', label='Y2')

[Link]('Number sqr')

[Link]()

2
[19]: import numpy as np

x = [i for i in range(1,11)]

y1 = [i**2 for i in range(1,11)]


y2 = [i**3 for i in range(1,11)]

x_indexes = [Link](len(x))
w = .3

[Link](x_indexes,y1, width=w, color='#123456', label='Y1')


[Link](x_indexes,y2, width=w, color='#000456', label='Y2')

[Link]('Number sqr')

[Link]()

3
[22]: import numpy as np

x = [i for i in range(1,11)]

y1 = [i**2 for i in range(1,11)]


y2 = [i**1.5 for i in range(1,11)]

x_indexes = [Link](len(x))
w = .3

[Link](x_indexes-w,y1, width=w, color='#123456', label='Y1')


[Link](x_indexes,y2, width=w, color='#000456', label='Y2')

[Link]('Number sqr')

[Link]()

4
[25]: import numpy as np

x = [i for i in range(1,11)]

y1 = [i**2 for i in range(1,11)]


y2 = [i**1.5 for i in range(1,11)]

x_indexes = [Link](len(x))
w = .3

[Link](x_indexes-w,y1, width=w, color='#123456', label='Y1')


[Link](x_indexes,y2, width=w, color='#000456', label='Y2')

[Link]()
[Link]('Number sqr')
[Link]()

[Link]()

5
[27]: x = [i for i in range(1,11)]

y = [i**2 for i in range(1,11)]

[Link](x,y)

[Link]('Number sqr')
[Link]('Numbers')
[Link]('Squares')

[Link]()

6
[ ]:

[ ]:

[ ]:

1.2 Histogram
[31]: ages = [15,20,24,28,32,19]

[Link](ages, bins=4, edgecolor='black')

# [Link]

[Link]('Ages')
[Link]('Range')
[Link]('Ages')

[Link]()

7
[33]: ages = [15,20,24,28,32,19]
bins = [10,15,20,25,30,35]

# more parameters for hist()


# [Link]

[Link](ages, bins=bins, edgecolor='black')

# [Link]

[Link]('Ages')
[Link]('Range')
[Link]('Ages')

[Link]()

8
[ ]:

[ ]:

[ ]:

1.3 Line Plot


[37]: x = list(range(1,11))
y = [i**2 for i in x]

# markers, colors, line styles -


# [Link]

[Link](x,y)

[Link]('Title')
[Link]('numbers')
[Link]('squares')
[Link]()

[Link]()

9
[38]: x = list(range(1,11))

y1 = [i**2 for i in x]
y2 = [i**3 for i in x]

[Link](x,y1)
[Link](x,y2)

[Link]('Title')
[Link]('numbers')
[Link]('squares')

[Link](['squares', 'cube'])

[Link]()

[Link]()

10
[40]: x = list(range(1,11))

y1 = [i**2 for i in x]
y2 = [i**3 for i in x]

[Link](x,y1,color='b', linestyle='--', marker='.', linewidth='4')


[Link](x,y2,color='r', linestyle='--', marker='.', linewidth='4')

[Link]('Title')
[Link]('numbers')
[Link]('squares')

[Link](['squares', 'cube'])

[Link]()

[Link]()

11
[49]: #[Link]('classic')

x = list(range(1,11))

y1 = [i**2 for i in x]
y2 = [i**3 for i in x]

[Link](x,y1, linestyle='--', marker='.', linewidth='4')


[Link](x,y2,linestyle='--', marker='.', linewidth='4')

[Link]('Title')
[Link]('numbers')
[Link]('squares')

[Link](loc=1)
[Link](['squares', 'cube'])

[Link]()

# [Link]

[Link]()

No handles with labels found to put in legend.

12
[41]: print([Link])

['Solarize_Light2', '_classic_test_patch', 'bmh', 'classic', 'dark_background',


'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn', 'seaborn-bright',
'seaborn-colorblind', 'seaborn-dark', 'seaborn-dark-palette', 'seaborn-
darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper',
'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-
white', 'seaborn-whitegrid', 'tableau-colorblind10']

[ ]:

[ ]:

[ ]:

13
1.4 Pie chart
[52]: slices = [70,30]

# more properties for pie()


# [Link]

[Link](slices)

[Link]('Pie Chart')
[Link]()

[53]: slices = [10,30,60]


labels = ['ten', 'thirty', 'sixty']

[Link](slices, labels=labels)

14
[Link]('Pie Chart')
[Link]()

[54]: slices = [10,30,60]


labels = ['ten', 'thirty', 'sixty']
colors = ['blue', 'red', 'yellow']

[Link](slices, labels=labels, colors=colors)

[Link]('Pie Chart')
[Link]()

15
[55]: slices = [10,30,60]
labels = ['ten', 'thirty', 'sixty']
colors = ['blue', 'red', 'yellow']

[Link](slices, labels=labels, colors=colors, wedgeprops={'edgecolor':'white'})

[Link]('Pie Chart')
[Link]()

16
[59]: slices = [10,30,60]
labels = ['ten', 'thirty', 'sixty']
colors = ['blue', 'red', 'yellow']
explode = [0.2,0,0]

[Link](slices, labels=labels, colors=colors, explode=explode,␣


,→wedgeprops={'edgecolor':'white'}, shadow=True)

[Link]('Pie Chart')
[Link]()

17
[ ]:

18

You might also like