Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to plot basic visualizations using pandas in python?

Description

To plot basic visualizations of data using pandas library in python.

Input

Pandas series of data.

Output

Bar chart, pie chart, scatter plot, histogram plot, etc.

Methods:

df.plot.bar()
df.plot.pie()
df.plot.scatter()
df.plot.area()
df.plot.hist()
df.plot.barh()

Process

   Import pandas library.

   Load the sample data.

  Plot the variables, that you want to visualize.

Sample Code

#import libraries
import pandas as pd
import matplotlib.pyplot as plt

#load the sample data from iris.csv file
data = pd.read_csv(‘/home/soft50/soft50/Sathish/practice/iris.csv’)

#Make it as a data frame
df = pd.DataFrame(data)

#variable to plot
X = df[‘sepal_length’]
y = df[‘sepal_width’]

#plot Line Graph
X.plot()
plt.title(“Line Graph”)
plt.show()
print(“\n”)

#Bar chart
def Bar_chart(X):
X = X.sample(30)
X.plot.bar()
plt.title(“Bar chart”)
plt.show()
Bar_chart(X)
print(“\n”)

#Pie chart
def Pie_chart(X):
X = X.sample(30)
X.plot.pie()
plt.title(“Pie chart”)
plt.show()
Pie_chart(X)
print(“\n”)

#Area plot
a = df.iloc[:,0:5]
a.plot.area()
plt.title(“Area chart”)
plt.show()
print(“\n”)

#Histogram plot
a.plot.hist(bins=20)
plt.title(“Histogram”)
plt.show()
print(“\n”)

#Scatter plot
a.plot.scatter(x=’sepal_length’,y=’sepal_width’)
plt.title(“Scatter plot”)
plt.show()
print(“\n”)

#Stacked Bar chart
def Stacked_Bar_chart(X):
X = X.sample(15)
X.plot.barh(stacked=True)
plt.title(“Stacked Bar chart”)
plt.show()
Stacked_Bar_chart(a)
print(“\n”)

Screenshots
plot basic visualizations using pandas in python
load the sample data from iris.csv file
#variable to plot
plot charts
import pandas as pd
Load the dataset
split the dataset from train and input