In [ ]:
import matplotlib.pyplot as plt
In [1]:
import matplotlib.pyplot as plt
x = [1,2,3]
y = [[1,2,3],[4,5,6],[7,8,9]]
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")
for i in range(len(y)):
plt.plot(x,[pt[i] for pt in y],label = 'id %s'%i)
plt.legend()
plt.show()
In [ ]:
x1 = [1,2,3]
y1 = [4,5,6]
x2 = [1,2,3]
y2 = [10,11,12]
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")
plt.plot(x1,y1,label = 'first line')
plt.plot(x2,y2,label = 'second line')
plt.legend()
plt.show()
In [ ]:
# bar charts
x = [2,4,6,8,10]
y = [7,9,8,1,2]
x2 = [1,3,5,7,9]
y2 = [4,1,2,9,6]
plt.bar(x,y,label='Bar1',color='red')
plt.bar(x2,y2,label='Bar2',color='k')
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")
plt.legend()
plt.show()
In [ ]:
# histograms - generally used to show distributions
pop_ages = [21,46,76,45,23,91,9,17,15,14,16,18,99,12,34,45,56,67,78,12,34,13,15,26,19,98,95,82]
ids = [x for x in range(len(pop_ages))]
# x axis not needed in histogram
bins = [0,10,20,30,40,50,60,70,80,90,100,110] #ranges of data
plt.hist(pop_ages,bins,histtype='bar',rwidth=0.8)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")
#plt.legend()
plt.show()
In [ ]:
# scatter plot - used to show relationship between two types of variables
x = [2,4,6,8,10]
y = [7,9,8,1,2]
plt.scatter(x,y,label='skitscat',color = 'k',marker = 'D',s=100)
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")
plt.legend()
plt.show()
In [ ]:
# stack plots
days = [1,2,3,4,5]
slp = [7,8,7,6,11]
eat = [5,2,1,1,1]
wrk = [7,8,8,8,1]
ply = [5,4,3,6,1]
plt.plot([],[],color='m',label = 'slp',linewidth=5)
plt.plot([],[],color='k',label = 'eat',linewidth=5)
plt.plot([],[],color='r',label = 'work',linewidth=5)
plt.plot([],[],color='c',label = 'ply',linewidth=5)
plt.stackplot(days, slp,eat,wrk,ply,colors=['m','k','r','c'])
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")
plt.legend()
plt.show()
In [ ]:
# pie charts
days = [1,2,3,4,5]
slp = [7,8,7,6,11]
eat = [5,2,1,1,1]
wrk = [7,8,8,8,1]
ply = [5,4,3,6,1]
slices = [7,2,2,13]
activities = ['slp','eat','work','ply']
cols = ['m','k','r','c']
plt.pie(slices,
labels= activities,
colors = cols,
shadow=True,
explode=(0,0.5,0,0),
autopct='%1.1f%%')
# plt.xlabel("X-axis")
# plt.ylabel("Y-axis")
plt.title("A test graph")
plt.legend()
plt.show()
In [ ]:
x,y = np.loadtxt("flnm.csv",delimiter = ',',unpack= True)
In [ ]:
import matplotlib.pyplot as plt
import pandas as pd
l = [(1,3),(0,2),(1,4),(0,1),(0,3)]
df = pd.DataFrame(l)
df.columns = ['a','b']
# bins = [0,1,2,3,4,5] #ranges of data
# plt.hist(list(df['b']),bins,histtype='bar',rwidth=0.8)
In [ ]:
plt.show()
In [ ]:
print(df['b'].value_counts().plot(kind='bar'))
In [ ]:
plt.close()
In [ ]:
plt.show()
In [ ]:
import matplotlib.pyplot as plt
import pandas as pd
l = [(1,3),(0,2),(1,4),(0,1),(0,3)]
df = pd.DataFrame(l)
df.columns = ['a','b']
In [ ]:
df.drop_duplicates(subset='a')
In [ ]:
import matplotlib.pyplot as plt
%matplotlib inline
In [ ]:
bins = [0,1,2,3,4,5] #ranges of data
plt.hist(list(df['b']),bins,histtype='bar',rwidth=0.8)
plt.show()
In [ ]: