Python CIA 2243024 - Jupyter Notebook

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

In 

[2]:

#Q.1)Plot a line segment from the point(-5,2)to the point(7/2,3)


import matplotlib.pyplot as plt
x_values =[-5,2]
y_values= [7/2,3]
plt.plot(x_values, y_values)
plt.plot(x_values,y_values,color="pink",marker="^",mec="red",linestyle="-",linewidth=(5))

Out[2]:

[<matplotlib.lines.Line2D at 0x1f16c964400>]

In [5]:

import matplotlib.pyplot as plt


x = [-5,1,5]
y = [7/2,3,0]
plt.plot(x,y)

Out[5]:

[<matplotlib.lines.Line2D at 0x1f16ca7a880>]
In [6]:

import matplotlib.pyplot as plt


x=[-5,1,5]
y=[7/2,3,0]
plt.plot(x,y)
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.show()
In [8]:

x=[-5,1,5]
y=[7/2,3,0]
plt.plot(x,y)
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.show()
plt.plot(x,y,color="pink", marker=".", linestyle="-.", lw=(4))

Out[8]:

[<matplotlib.lines.Line2D at 0x1f16cc3ae80>]
In [18]:

#Q.2import matplotlib.pyplot as plt


import matplotlib.pyplot as plt
import numpy as np

# Set x-axis range from -75 to 50


x = np.linspace(-75, 50, 500)

# Equation for parabola with a positive leading coefficient (open upward)


y1 = x**2 + 4 * x - 5

# Equation for parabola with a negative leading coefficient (open downward)


y2 = -x**2 + 4 * x - 5

# Plot the parabolas


plt.plot(x, y1, label='Open upward')
plt.plot(x, y2, label='Open downward')

# Add labels, title and legend


plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.title('Parabolas')
plt.legend()

# Show the plot


plt.show()
#To determine the symmetric property, we need to check if the parabola is symmetric about t
#For the parabola open upward, it is symmetric about the x-axis.
#For the parabola open downward, it is symmetric about the origin.
In [20]:

#Q.3)
import matplotlib.pyplot as plt
import numpy as np

# Set y-axis range from -5 to 20


y = np.linspace(-5, 20, 500)

# Equation for parabola with a positive leading coefficient (open rightward)


x1 = (y**2 - 4 * y + 5)/4

# Equation for parabola with a negative leading coefficient (open leftward)


x2 = (-y**2 + 4 * y + 5)/4

# Plot the parabolas


plt.plot(x1, y, label='Open rightward')
plt.plot(x2, y, label='Open leftward')

# Add labels, title and legend


plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.title('Parabolas')
plt.legend()

# Show the plot


plt.show()
#Classifying the properties of the parabolas:

#For the parabola open rightward:

#Vertex: (1, 2)
#Focus: (1 + sqrt(15)/4, 2)
#Directrix: y = 0
#Latus rectum: 4
#For the parabola open leftward:

#Vertex: (-1, 2)
#Focus: (-1 - sqrt(15)/4, 2)
#Directrix: y = 0
#Latus rectum: 4
In [10]:

#Q.4)
import math

print(math.sin(math.radians(30)))
print(math.sin(math.radians(0)))
print(math.sin(math.radians(60)))
print(math.sin(math.radians(45)))
print(math.sin(math.radians(90)))
print(math.sin(math.degrees(30)))
print(math.sin(math.degrees(0)))
print(math.sin(math.degrees(60)))
print(math.sin(math.degrees(45)))
print(math.sin(math.degrees(90)))

0.49999999999999994

0.0

0.8660254037844386

0.7071067811865476

1.0

-0.4097717985741408

0.0

0.7475778912844228

0.8060754911159176

-0.9540914674728181

In [11]:

print(math.cos(math.radians(30)))
print(math.cos(math.radians(0)))
print(math.cos(math.radians(60)))
print(math.cos(math.radians(45)))
print(math.cos(math.radians(90)))
print(math.cos(math.degrees(30)))
print(math.cos(math.degrees(0)))
print(math.cos(math.degrees(60)))
print(math.cos(math.degrees(45)))
print(math.cos(math.degrees(90)))

0.8660254037844387

1.0

0.5000000000000001

0.7071067811865476

6.123233995736766e-17

-0.9121880689272984

1.0

0.6641741461866275

-0.5918127259718502

-0.2995153947555356

In [12]:

#6. The revenue and profit for fortune companies are as follows. Draw the scatter plots in
#same window and give inference about it.
x=9823.5,5661.4,3250.4,2959.1,2510.8,2071.6,2056.1,1705.3,1703.6, 1687.7,1667.4, 1660.3, 16
y=806,584.8,195.4,212.6,19.1,18.5,1.6,182.8,183.8,344.4,132.8,117.2,84.6,226.1,55.8,121.1,3
plt.scatter(x,y)
plt.show()

In [22]:

#Q.7)
x=['Maths', 'English', 'History', 'Geography']
labels=['a','b','c','d','e']
y=[100,98,87,96]
plt.bar(x,y)

Out[22]:

<BarContainer object of 4 artists>


In [ ]:

In [24]:

#Q.8)
import matplotlib.pyplot as plt
import numpy as np

# generate random data for 500 students


np.random.seed(0) # set seed for reproducibility
heights = np.random.normal(loc=170, scale=10, size=500)
weights = np.random.normal(loc=60, scale=10, size=500)

# plot histogram for heights


n, bins, patches = plt.hist(heights, bins=20, edgecolor='black', alpha=0.7)

# add labels and title


plt.xlabel('Height (cm)')
plt.ylabel('Frequency')
plt.title('Histogram of Heights for 500 Students')

# show plot
plt.show()
In [26]:

#Q.9)
import matplotlib.pyplot as plt
import numpy as np

# set seed for reproducibility


np.random.seed(0)

# create subplot grid


fig, ax = plt.subplots(2, 3, figsize=(12, 8))

# plot random arrays


lengths = [4, 5, 6, 7, 10, 13]
for i, l in enumerate(lengths):
ax[i//3, i%3].plot(np.random.randn(l))
ax[i//3, i%3].set_title("Length = {}".format(l))

# show plot
plt.tight_layout()
plt.show()
In [27]:

#Q.10)
import matplotlib.pyplot as plt
import numpy as np

# set seed for reproducibility


np.random.seed(0)

# plot first 3 random arrays


lengths = [4, 5, 6]
fig, ax = plt.subplots(1, 3, figsize=(12, 4))
for i, l in enumerate(lengths):
ax[i].plot(np.random.randn(l))
ax[i].set_title("Length = {}".format(l))

# plot next 3 random arrays


lengths = [7, 10, 13]
fig, ax = plt.subplots(1, 3, figsize=(12, 4))
for i, l in enumerate(lengths):
ax[i].plot(np.random.randn(l))
ax[i].set_title("Length = {}".format(l))

# show plots
plt.tight_layout()
plt.show()

In [ ]:

#Q.6)

You might also like