from matplotlib import pyplot as plt
%matplotlib inline
a=linspace(10,20,15)
a
array([ 10. , 10.71428571, 11.42857143, 12.14285714, 12.85714286, 13.57142857, 14.28571429, 15. , 15.71428571, 16.42857143, 17.14285714, 17.85714286, 18.57142857, 19.28571429, 20. ])
b=linspace(20,30,15)
b
array([ 20. , 20.71428571, 21.42857143, 22.14285714, 22.85714286, 23.57142857, 24.28571429, 25. , 25.71428571, 26.42857143, 27.14285714, 27.85714286, 28.57142857, 29.28571429, 30. ])
plt.plot(a,b)
[<matplotlib.lines.Line2D at 0x7f313736bda0>]
plt.plot(a,b,marker='*',linestyle='solid',color='red')
plt.title("First graph")
plt.ylabel("Random numbers")
plt.xlabel("Not so random numbers")
plt.show()
year=[n for n in range(2010, 2021,3)]
year
[2010, 2013, 2016, 2019]
population=[1.2,1.25,1.3,1.35]
plt.plot(year,population,color='green',marker='o')
plt.title("Poplualtion Explosion!")
plt.xlabel("Years")
plt.ylabel("Population in Billions")
plt.show()
pop=[1.37,1.25,0.3]
country=['China','India','USA']
x=[i+0.2 for i,_ in enumerate(country)]
plt.bar(x,pop,color='red')
plt.title("Population in Year $2013$")
plt.ylabel("# in billions")
plt.xticks([i+0.2 for i,_ in enumerate(country)],country)
plt.show()
plt.pie(pop)
plt.title("Popluation in 2013")
plt.legend(country,loc='best')
plt.show()
x=linspace(-pi,pi,100)
plt.plot(x,sin(x),'ro',label='dotted sin curve')
plt.plot(x,cos(x),'g--',label='dashed cos curve')
plt.legend(loc=2)
plt.title("Line charts")
plt.xlabel("$pi$ value")
plt.show()
followers=[100,30,20,3,0]
daily_tweets=[35,20,9,2,1]
plt.scatter(followers,daily_tweets)
<matplotlib.collections.PathCollection at 0x7f9e1f27b710>