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

matplotlib1 - Jupyter Notebook

Uploaded by

2361
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

matplotlib1 - Jupyter Notebook

Uploaded by

2361
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

11/28/23, 2:57 PM matplotlib - Jupyter Notebook

In [2]: import numpy as np


for i in a.arange(0,1,0.1):
print(i)

0.0
0.1
0.2
0.30000000000000004
0.4
0.5
0.6000000000000001
0.7000000000000001
0.8
0.9

In [6]: for i in a.linspace(1,10,12):


print(i)

1.0
1.8181818181818183
2.6363636363636367
3.4545454545454546
4.272727272727273
5.090909090909091
5.909090909090909
6.7272727272727275
7.545454545454546
8.363636363636363
9.181818181818182
10.0

In [12]: x=[1,2,3,4,5]
y=[2,3,2,3,2]
print(x)
print(y)

[1, 2, 3, 4, 5]
[2, 3, 2, 3, 2]

In [13]: from pylab import plot


plot(x,y,marker='o')

Out[13]: [<matplotlib.lines.Line2D at 0x1c120e26e88>]

localhost:8888/notebooks/Documents/arun/mathsprogram/matplotlib.ipynb 1/5
11/28/23, 2:57 PM matplotlib - Jupyter Notebook

In [11]: plot(x,y,'o')

Out[11]: [<matplotlib.lines.Line2D at 0x1c120daff08>]

In [ ]: #draw a graph of avg annual temperature from yr 2000 to 2012 which are
#53.9,56.3,56.4,53.4,54.5,55.8,56.8,55.0,55.3,54.0,56.7,56.4,57.3

In [15]: yr=[2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012]
avg_temp=[53.9,56.3,56.4,53.4,54.5,55.8,56.8,55.0,55.3,54.0,56.7,56.4,57.3]
print(avg_temp)
print(yr)

[53.9, 56.3, 56.4, 53.4, 54.5, 55.8, 56.8, 55.0, 55.3, 54.0, 56.7, 56.4, 5
7.3]
[2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2
012]

In [17]: plot(yr,avg_temp,marker='o')

Out[17]: [<matplotlib.lines.Line2D at 0x1c120f06e88>]

localhost:8888/notebooks/Documents/arun/mathsprogram/matplotlib.ipynb 2/5
11/28/23, 2:57 PM matplotlib - Jupyter Notebook

In [18]: plot(yr,avg_temp,marker='*')

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

In [ ]: ​

In [ ]: #now programming using matplotlib


#plot() title() xlabel() ylabel() axis() grid() subplot() legend() show()

In [26]: import matplotlib.pyplot as plt


x=[2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012]
y=[53.9,56.3,56.4,53.4,54.5,55.8,56.8,55.0,55.3,54.0,56.7,56.4,57.3]
plt.title("temperature graph")
plt.plot(x,y)
plt.xlabel("Years")
plt.ylabel("Temperature")
plt.grid() #for grid view

localhost:8888/notebooks/Documents/arun/mathsprogram/matplotlib.ipynb 3/5
11/28/23, 2:57 PM matplotlib - Jupyter Notebook

In [30]: import numpy as np


x=[0,1,2,3,4,5,6,7,8,9,10]
y=np.sin(x)
plt.plot(x,y)
plt.grid()

In [34]: x=np.linspace(0,2*np.pi,200)
y=np.sin(x)
plt.plot(x,y)

Out[34]: [<matplotlib.lines.Line2D at 0x1c12230d708>]

localhost:8888/notebooks/Documents/arun/mathsprogram/matplotlib.ipynb 4/5
11/28/23, 2:57 PM matplotlib - Jupyter Notebook

In [42]: x=np.linspace(0,2*np.pi,200)
y=np.sin(x)
z=np.cos(x)
plt.subplot(2,2,1)
plt.title("Sinx")
plt.plot(x,y)
plt.subplot(2,1,2)
plt.title("Cosx")
plt.plot(x,z)

Out[42]: [<matplotlib.lines.Line2D at 0x1c1227291c8>]

In [ ]: ​

localhost:8888/notebooks/Documents/arun/mathsprogram/matplotlib.ipynb 5/5

You might also like