0% found this document useful (0 votes)
11 views10 pages

PHY1003 Assignment 1

It has 10 python codes for plotting basic 2D and 3D graphs

Uploaded by

adx.222005
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)
11 views10 pages

PHY1003 Assignment 1

It has 10 python codes for plotting basic 2D and 3D graphs

Uploaded by

adx.222005
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/ 10

ASSIGNMENT 1

Question 1: Basic 2D Line Plot

import matplotlib . pyplot as plt


days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday']
temp = [22,24,21,19,20,23,25]
plt.plot ( days,temp,marker ='o',linestyle ='-',color ='green')
plt.xlabel ("Days")
plt.ylabel ("Temperature")
plt. tle ("Temperature Data")
plt.show ()
Question 2: Multiple Line Plot

import matplotlib.pyplot as plt


months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Dec']
store_A = [500, 700, 800, 650, 900, 1000, 1100, 950, 1050, 1200, 1300, 1400]
store_B = [400, 600, 700, 800, 750, 900, 950, 850, 900, 1000, 1100, 1150]
plt.figure(figsize=(10, 6))
plt.plot(months, store_A, label='Store A', marker='o', linestyle='-', color='blue')
plt.plot(months, store_B, label='Store B', marker='o', linestyle='-',
color='green')
plt. tle('Revenue Data')
plt.xlabel('Months')
plt.ylabel('Revenue')
plt.legend()
plt.show()
Question 3: Bar Graph

import matplotlib.pyplot as plt


books = ['Fic on', 'Non-Fic on', 'Mystery', 'Sci-Fi', 'Fantasy']
copies = [120, 80, 60, 90, 70]
plt.bar(books, copies , color ='red')
plt.xlabel ("Books Genre")
plt.ylabel ("No. of Copies Sold")
plt. tle ("Books Sold by Genre")
plt.show ()
Question 4: Scatter Plot

import matplotlib . pyplot as plt


height = [170,180,175,160,165,185]
weight = [65,80,75,55,60,90]
plt.sca er( height,weight,color ='red')
plt.xlabel ("Height(in cms)")
plt.ylabel ("Weight(in kgs)")
plt. tle ("Height-Weight Data")
plt.show ()
Question 5: 3D Scatter Plot

import matplotlib.pyplot as plt


from mpl_toolkits.mplot3d import Axes3D
x= [1,2,3,4,5]
y= [2,3,1,5,4]
z= [3,1,2,4,5]
fig= plt.figure()
ax = fig.add_subplot(111, projec on='3d')
ax.sca er(x,y,z,c='b',marker='o')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
ax.set_ tle('3D Sca er Plot')
plt.show()
Question 6: 3D Surface Plot

import matplotlib.pyplot as plt


from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x= np.arange(-5,6,1)
y= np.arange(-5,6,1)
x, y= np.meshgrid(x,y)
z= x**2+y**2
fig= plt.figure()
ax = fig.add_subplot(111, projec on='3d')
ax.plot_surface(x,y,z,cmap='viridis')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
ax.set_ tle('3D Surface Plot')
plt.show()
Question 7: Pie Chart
import matplotlib.pyplot as plt
companies = ['Company A', 'Company B', 'Company C', 'Company D']
market_share = [35, 25, 20, 25]
plt.figure(figsize=(7,7))
plt.pie(market_share, labels=companies, autopct='%1.1f%%', shadow=True,
startangle=140)
plt. tle('Market Share')
plt.show()
Question 8: Histogram

import matplotlib.pyplot as plt


ages = [23, 45, 23, 34, 25, 30, 40, 45, 23, 22, 24, 31, 38, 40, 25, 28, 30, 29, 22,
26]
plt.hist(ages, bins=8, color='red',edgecolor='black')
plt.xlabel('Ages')
plt.ylabel('Frequency')
plt. tle('Age Distribu on')
plt.show()
Question 9: 3D Wireframe Plot
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x= np.linspace(-5,5,1000)
y= np.linspace(-5,5,1000)
x, y= np.meshgrid(x,y)
z= np.sin(np.sqrt(x**2+y**2))
fig= plt.figure()
ax = fig.add_subplot(111, projec on='3d')
ax.plot_surface(x,y,z,cmap='viridis')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')
ax.set_zlabel('Z Axis')
ax.set_ tle('3D Wireframe Plot')
plt.show()
Question 10: Annotated Scatter Plot

import matplotlib . pyplot as plt


height = [170,180,175,160,165,185]
weight = [65,80,75,55,60,90]
plt.sca er( height,weight,color ='red')
plt.xlabel ("Height(in cms)")
plt.ylabel ("Weight(in kgs)")
plt. tle ("Height-Weight Data")
for i in range(len(height)):
plt.annotate(f'Person {i + 1}', (height[i], weight[i]), textcoords="offset points",
xytext=(0, 5), ha='center')
plt.show()

You might also like