You are on page 1of 3

Creating sublots in single figure

import pandas as pd

import matplotlib.pyplot as plt

#read the csv file into the dataframe

df= pd.read_excel('medals_2021.xlsx',usecols=['Team/NOC','Gold','Silver','Bronze','Total'])

#display the dataframe

d=df.head(n=10)`

y=d['Team/NOC']

x1=d['Gold']

x2=d['Silver']

x3=d['Bronze']

x4=d['Total']

print(d)

fig, ax = plt.subplots(2, 2)

ax[0, 0].plot(x1,y,color='g') #row=0, col=0

ax[1, 0].plot(x2,y,color='k') #row=1, col=0

ax[0, 1].plot(x3,y,color='b') #row=0, col=1

ax[1, 1].plot(x4,y,color='r') #row=1, col=1

plt.yticks(rotation=45)

fig.show()

Creating different types of charts


import pandas as pd

import matplotlib.pyplot as plt

#reading the CVS file into dataframe

df=pd.read_csv('iris.csv')

#print(df)

#print(df.values)

#print(df.describe())

#l=df.loc[:,'species']

#print(l)
#h=df.head(n=10)

#t=df.tail(n=5)

#print(h)

#print(t)

#fetching specific columns

l1=df.loc[:,'sepal_length']

l2=df.loc[:,'petal_length']

l3=df.loc[:,'sepal_width']

a=df.loc[:,'petal_width']

#line plot

#plt.plot(l1,l2,color='m',linestyle=':')

#scatter plot

#plt.scatter(l1,l2,s=8,c='green')

#plt.scatter(l1,l3,s=20,c='red')

#plt.scatter(l2,a,s=40)

#histogram using pyplot

#plt.hist(l1)

#plt.hist(l2)

#plt.hist(l3)

#plt.hist(a)

#histogram using dataframe

#df['sepal_length'].hist()

#df['sepal_width'].hist()

#df['petal_length'].hist()

#df['petal_width'].hist()

#bar plot

plt.bar(l1,l3,color='DarkMagenta')

plt.bar(l2,a,color='DarkOrchid')

#adding details to the plot

plt.title('IRIS FLOWER DATA VISUALIZATION')

plt.legend(['sepal_length', 'petal_length'])
plt.xlabel('Sepal length')

plt.ylabel('Petal length')

plt.show()

You might also like