You are on page 1of 3

Assignment-4

1.Generate a random array of 50 integers and display them using a line chart,scatter
chart,histogram and box plot
*-print histogram
import matplotlib.pyplot as plt
import numpy as np
data=np.random.randn(50)
plt.hist(data)
plt.hist(data,facecolor='y',linewidth=2,edgecolor='k',bins=30,alpha=0.6)

*-print line chart


import numpy as np
x=np.linspace(0,50,100)
y=x*np.linspace(100,150,100)
plt.plot(x,y)
plt.plot(x,y,marker='*',markersize=3,c='b',label='normal')
plt.grid(True)
plt.legend()

*-print Scatter plot


import matplotlib.pyplot as plt
x=np.random.randn(50)
y=np.random.randn(50)
size=150*np.random.randn(50)
colors=100*np.random.randn(50)
plt.scatter(x,y,s=size,c=colors,marker='*',alpha=0.7)

*-print bar plot


import matplotlib.pyplot as plt
data=np.random.randn(50)
plt.boxplot(data,vert=False)
plt.show()

4.Write a python program to create a pie plot to get frequency of the three species of the iris
data
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
iris = pd.read_csv("E://iris.csv")
ax=plt.subplots(1,1,figsize=(10,8))
sns.countplot('variety',data=iris)
plt.title("Iris variety Count")
plt.show()
5.Write a python program to create a pie plot to get frequency of the three species of the iris
data
import pandas as pd
import matplotlib.pyplot as plt
iris = pd.read_csv("E://iris.csv")
ax=plt.subplots(1,1,figsize=(10,8))
iris['variety'].value_counts().plot.pie(explode=[0.1,0.1,0.1],autopct='%1.1f%%',shadow=True,figsi
ze=(10,8))
plt.title("Iris Species %")
plt.show()

6.write a python program to create a histogram of three species of the iris data
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
df=pd.read_csv("E://iris.csv")
sns.histplot(df["variety"],color="green")
plt.show()

Set B
1) Write a python program to create a graph to find relationship between petal lenght and petal
width.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
df=pd.read_csv("E://iris.csv")
plt.figure(figsize=(10,5))
plt.title('Relationship between the petal lenth and petal width ')
sns.boxplot(y="petal.length",x="petal.width",data=df)
plt.show()

2) Write a python program to draw scatter plots to compare two features of iris dataset.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
df=pd.read_csv("E://iris.csv")
plt.figure(figsize=(10,5))
plt.title('Comparison between various species based on petal lenght and width')
sns.scatterplot(df['petal.length'],df['petal.width'],hue=df['variety'],s=50)
plt.show()
3)write a python program to create box plots see how each feature i.e. Sepal Length,width,Petal
Length,width are distributed across the three species.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
df=pd.read_csv("E://iris.csv")
fig,axes=plt.subplots(2,2,figsize=(10,6))
sns.boxplot(y="petal.length",x="variety",data=df,orient='v',ax=axes[0,0])
sns.boxplot(y="petal.width",x="variety",data=df,orient='v',ax=axes[0,1])
sns.boxplot(y="sepal.length",x="variety",data=df,orient='v',ax=axes[1,0])
sns.boxplot(y="sepal.width",x="variety",data=df,orient='v',ax=axes[1,1])
plt.show()

You might also like