In [2]:
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 [7]:
# 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 [10]:
# 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')

plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("A test graph")
plt.legend()
plt.show()