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

matplotlib - Jupyter Notebook

Uploaded by

xometex256
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)
9 views

matplotlib - Jupyter Notebook

Uploaded by

xometex256
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/ 7

6/16/24, 5:50 PM matplotlib - Jupyter Notebook

In [1]: import numpy as np


import pandas as pd
import matplotlib.pyplot as plt

In [2]: a = np.arange(0,10)

In [3]: a

Out[3]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [4]: plt.plot(a)

Out[4]: [<matplotlib.lines.Line2D at 0x779fc74c11d0>]

localhost:8888/notebooks/Untitled Folder/matplotlib.ipynb 1/7


6/16/24, 5:50 PM matplotlib - Jupyter Notebook

In [10]: plt.plot(a, 'ro')

Out[10]: [<matplotlib.lines.Line2D at 0x779fc2a7a650>]

localhost:8888/notebooks/Untitled Folder/matplotlib.ipynb 2/7


6/16/24, 5:50 PM matplotlib - Jupyter Notebook

In [17]: plt.axis([0,10,0,15])
plt.plot(a, 'ro')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.text(2,10,"This is the location")
plt.title('My First Plot')
plt.grid(True)

localhost:8888/notebooks/Untitled Folder/matplotlib.ipynb 3/7


6/16/24, 5:50 PM matplotlib - Jupyter Notebook

In [18]: a = np.arange(0,20,2)
b = np.arange(1,20,2)
plt.plot(a,'r')
plt.plot(b,'b')

Out[18]: [<matplotlib.lines.Line2D at 0x779fc2753810>]

localhost:8888/notebooks/Untitled Folder/matplotlib.ipynb 4/7


6/16/24, 5:50 PM matplotlib - Jupyter Notebook

In [21]: plt.subplot(221)
plt.plot(a,'r')
plt.subplot(222)
plt.plot(b,'b')
plt.subplot(223)
plt.plot(a,'g')
plt.subplot(224)
plt.plot(b,'y')

Out[21]: [<matplotlib.lines.Line2D at 0x779fc2422350>]

In [22]: data = np.random.randint(0,100,100)

In [23]: data

Out[23]: array([36, 53, 5, 55, 78, 44, 24, 19, 31, 98, 7, 47, 51, 63, 94,
3, 8,
6, 21, 9, 35, 96, 69, 78, 82, 12, 9, 93, 15, 87, 26, 8,
11, 26,
92, 38, 9, 56, 25, 11, 23, 80, 64, 44, 38, 58, 8, 72, 80,
71, 25,
18, 53, 26, 16, 47, 97, 0, 16, 8, 0, 74, 49, 49, 84, 75,
46, 89,
81, 49, 25, 42, 2, 32, 23, 17, 71, 66, 82, 10, 79, 76, 38,
6, 69,
29, 11, 36, 57, 99, 36, 17, 19, 64, 94, 33, 37, 94, 52, 4
5])

localhost:8888/notebooks/Untitled Folder/matplotlib.ipynb 5/7


6/16/24, 5:50 PM matplotlib - Jupyter Notebook

In [24]: plt.hist(data, bins=10)

Out[24]: (array([15., 13., 11., 11., 10., 8., 6., 9., 8., 9.]),
array([ 0. , 9.9, 19.8, 29.7, 39.6, 49.5, 59.4, 69.3, 79.2, 89.
1, 99. ]),
<BarContainer object of 10 artists>)

localhost:8888/notebooks/Untitled Folder/matplotlib.ipynb 6/7


6/16/24, 5:50 PM matplotlib - Jupyter Notebook

In [33]: data = [30,20,40,10]


c = ['red','green','blue','yellow']
labels = ['red','green','blue','yellow']
plt.legend(['r','g','b','y'])
plt.pie(data,colors=c,labels=labels)
plt.show()

In [ ]:

localhost:8888/notebooks/Untitled Folder/matplotlib.ipynb 7/7

You might also like