import numpy as np
from matplotlib import pyplot as plt
x = np.arange(1,11)
x
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
y=2*x
y
array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20])
plt.plot(x,y)
plt.show()
plt.plot(x,y)
plt.title("Line Plot Example")
plt.xlabel("x-label")
plt.ylabel("y-label")
plt.show()
plt.plot(x,y,color="g",linestyle=":",linewidth=2)
plt.title("Line Plot Example")
plt.xlabel("Sales")
plt.ylabel("Transactions")
plt.show()
x = np.arange(1,11)
y1 = 2 * x
y2 = 3 * x
plt.plot(x,y1,color="g",linestyle=":",linewidth=2)
plt.plot(x,y2,color="r",linestyle="-.",linewidth=3)
plt.title("Line Plot Example")
plt.xlabel("Sales")
plt.ylabel("Transactions")
plt.grid(True)
plt.show()
plt.subplot(1,2,1)
plt.plot(x,y1,color="g")
plt.subplot(1,2,2)
plt.plot(x,y2,color="r")
plt.show()
#Bar chart example
transDict = {"Jan":33000,"Feb":23800,"March":40000,"April":57900}
months = list(transDict.keys())
sales = list(transDict.values())
plt.bar(months,sales)
plt.show()
transDict = {"Jan":33000,"Feb":23800,"March":40000,"April":57900}
months = list(transDict.keys())
sales = list(transDict.values())
plt.barh(months,sales,color="g")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.grid(True)
plt.show()
transDict = {"Jan":33000,"Feb":23800,"March":40000,"April":57900}
months = list(transDict.keys())
sales = list(transDict.values())
plt.bar(months,sales,color="r")
plt.xlabel("Month")
plt.ylabel("Sales")
plt.grid(True)
plt.show()
#Scatter plot
x = [10,20,30,40,50,60,70,80,90]
y = [8,1,7,2,0,3,7,3,2]
plt.scatter(x,y)
plt.show()
x = [10,20,30,40,50,60,70,80,90]
y = [8,1,7,2,0,3,7,3,2]
plt.scatter(x,y,marker="*",c="orange",s=200)
plt.show()
x = [10,20,30,40,50,60,70,80,90]
y1 = [8,3,7,1,4,9,3,6,0]
y2 = [1,2,3,8,6,5,3,9,6]
plt.scatter(x,y1,marker="*",c="orange",s=200)
plt.scatter(x,y2,marker=".",c="red",s=300)
plt.show()
x = [10,20,30,40,50,60,70,80,90]
y1 = [8,3,7,1,4,9,3,6,0]
y2 = [1,2,3,8,6,5,3,9,6]
plt.subplot(1,2,1) #single row and 2 columns and left side
plt.scatter(x,y1,marker="*",c="orange",s=200)
plt.subplot(1,2,2) #single row and 2 columns and right side
plt.scatter(x,y2,marker=".",c="red",s=300)
plt.show()
x = [10,20,30,40,50,60,70,80,90]
y1 = [8,3,7,1,4,9,3,6,0]
y2 = [1,2,3,8,6,5,3,9,6]
plt.subplot(2,1,1) #2 rows single column top side
plt.scatter(x,y1,marker="*",c="orange",s=200)
plt.subplot(2,1,2) #2 rows single column bottom side
plt.scatter(x,y2,marker=".",c="red",s=300)
plt.show()
#histogram example
data = [1,3,3,3,3,9,9,5,4,4,8,8,8,6,7]
plt.hist(data)
plt.show()
#load data from csv and display histogram chart
import pandas as pd
df = pd.read_csv("E:\\PyExa\\iris.csv")
plt.hist(df["sepal.length"],bins=30,color="r")
plt.show()
import pandas as pd
df = pd.read_csv("E:\\PyExa\\iris.csv")
plt.hist(df["sepal.length"],bins=30,color="r")
plt.hist(df["petal.width"],color="green")
plt.show()
No comments:
Post a Comment