In [1]:
import matplotlib.pyplot as plt

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 [4]:
# 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 [5]:
# 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 [3]:
# 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 [25]:
# 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 [30]:
# 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 [ ]:
# customization of matplotlib plots