Skip to main content

Posts

Showing posts with the label Python

Draw a Pie Chart using python Matplotlib

Draw a Pie Chart using python Matplotlib Code : import matplotlib.pyplot as plt

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [20, 35, 40, 150]
explode = (0, 0.1, 0, 0)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)
ax1.axis('equal')

plt.show()
Output :

Draw a Histogram using Python Matplotlib

Draw a Histogram using Python Matplotlib Code :  from matplotlib import pyplot as plt
import numpy as np 

a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])
plt.hist(a, bins = [0,20,40,60,80,100])
plt.title("histogram")
plt.show()
Output :

Draw a Bar Graph using Python Matplotlib

Draw a Bar Graph using Python Matplotlib Code :  import numpy as np
from matplotlib import pyplot as plt
x=[1,2,3,4,5]
print(x)
y = [1,1,3,6,1]
print(y) plt.plot(x,y,"ob")
plt.bar(x,y)
plt.show()
Output :

Read CSV File using Python Pandas

Read CSV File using Python Pandas CSV File : Code : import pandas as pd
import numpy as np

file_01 = 'moviedaily.dat.txt'
data_01 = pd.read_csv("moviedaily.dat.txt")
print(data_01.head())

Output :

Draw a graph using Matplotlib

How To Draw a graph using Matplotlib Code :
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

Output :

Draw a Static line graph Using Matplotlib

Draw a graph with static data using matplotlib
Code:
import matplotlib.pyplot as plt 
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()
output: