Professional Documents
Culture Documents
import matplotlib.pyplot as pl
a=[1,2,3,4]
b=[2,4,6,8]
c=[1,4,9,16]
pl.xlabel("Some Values")
pl.ylabel("Doubled Values")
pl.title("A Simple Line chart")
pl.plot(a,b,color='y')
pl.show()
color ( line/marker)
marker type
marker size
import matplotlib.pyplot as plt
x = [1,2,3,4,5,6]
y = [2,4,1,5,2,6]
plt.plot(x, y, color='green', linestyle='dashed', linewidth =
3,marker='X', markeredgecolor='blue', markersize=12)
#setting x and y axis range
plt.ylim(1,8)
plt.xlim(1,8)
plt.xlabel('x - axis')
plt.ylabel('y - axis')
plt.title('Some cool customizations!')
plt.show()
#color-line,marker
#marker type
#marker size
x=np.arange(0.,10,0.1)
a=np.cos(x)
b=np.sin(x)
plt.plot(x,a,'b')
plt.plot(x,b,'g')
plt.show()
p=[1,2,3,4]
q=[2,4,6,8]
#plt.plot(p,q,'r+',linestyle='solid')
plt.plot(p,q,'r+',linestyle='solid',markeredgecolor='b')
plt.show()
"""
#To plot an algebraic expression 10x+14 using chart
x=np.arange(12,20)
y=10*x+14
plt.title("Graph for an algebraic expression")
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.plot(x,y,color='m')
plt.show()
"""
import matplotlib.pyplot as plt
import numpy as np
y=np.arange(1,3)
plt.plot(y,'--',y+1,'-.',y+2,':')
plt.show()
plt.plot(y,color='y')
plt.plot(y+1,'m')
plt.plot(y+2,'c')
plt.show()
#example 3.1
import numpy as np
import matplotlib.pyplot as plt
a=np.arange(1,20,1.25)
b=np.log(a)
plt.plot(a,b)
plt.xlabel("Random values")
plt.ylabel("Logarithmic Values")
plt.show()
plt.bar(a,b)
plt.xlabel("Values")
plt.ylabel("Doubles")
plt.title("Bar Graph")
plt.show()
plt.bar(a,c)
plt.xlabel('Values')
plt.ylabel('Squares')
plt.title("Squares of Numbers")
plt.show()
import matplotlib.pyplot as plt
Cities=['Delhi','Mumbai','Bangalore','Hyderabad']
Population=[23456123,20083104,18456123,13411093]
plt.bar(Cities,Population,width=[0.25,0.5,0.6,0.9],color=['red','b
','g','black'])
plt.xlabel('Cities')
plt.ylabel('Population')
plt.show()
#Example 11
import matplotlib.pyplot as plt
Info=['Gold','Silver','Bronze','Total']
Australia=[80,59,59,198]
plt.barh(Info,Australia,color='orange')
plt.xlabel("Medals Type")
plt.ylabel("Australia Medal Count")
plt.show()
plt.xlabel("Medals Type")
plt.ylabel("Australia Medal Count")
plt.show()
import numpy as np
import matplotlib.pyplot as plt
Val=[[5.,25.,45.,20.],[4.,23.,49.,17.],[6.,22.,47.,19.]]
# Val[0] Val[1] Val[2]
X=np.arange(4)
#X=[0,1,2,3]
#Step1 : specify label for each range beoing plotted using label
argument
plt.bar(X+0.00,Val[0],color='b',width=0.25,label='range1')
plt.bar(X+0.25,Val[1],color='g',width=0.25,label='range2')
plt.bar(X+0.5,Val[2],color='r',width=0.25,label='range3')
#import numpy as np
import matplotlib.pyplot as plt
X=[0,1,2,3]
#X=np.arange(4)
Y=[5.,25.,45.,20.]
plt.xlim(-2.0,4.0)
plt.ylim(0,60)
plt.xlabel(" X - axis")
plt.ylabel(" Y - axis")
plt.bar(X,Y)
plt.title("A Simple Bar Chart")
plt.show()
Amount A to F =[8000,12000,9800,11200,15500,7300]
(a) Create a bar chart showing collection amount
(b) Plot the collected amount vs days using a bar chart
(c) Plot the collected amount vs sections using a bar chart
"""
"""
plt.plot(X,Data[0],color='m',label='range1')
plt.plot(X,Data[1],color='b',label='range2')
plt.plot(X,Data[2],color='g',label='range3')
plt.legend(loc='upper right')
plt.title("Multirange Line Chart")
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
plt.savefig("multibar.pdf")
Parameters of hist()
x , bins , cumulative : bool, histtype - ('bar','barstacked',
'step','stepfilled' ),orientation - ('horizontal', 'vertical' )
#plt.hist(x,bins=None,cumulative=False,histtype='bar','barstack
ed','step','stepfilled',align='mid',orientation='vertical'
'horizontal')
#Example 27 page 212
# A survey gathers height and weight of 100 participants and
recorded the participants ages a:
import matplotlib.pyplot as pl
import numpy as np
x=[1,1,2,3,3,5,7,8,9,10,
10,11,11,13,13,15,16,17,18,18,
18,19,20,21,21,23,24,24,25,25,
25,25,26,26,26,27,27,27,27,27,
29,30,30,31,33,34,34,34,35,36,
36,37,37,38,38,39,40,41,41,42,
43,44,45,45,46,47,48,48,49,50,
51,52,53,54,55,55,56,57,58,60,
61,63,64,65,66,68,70,71,72,74,
75,77,81,83,84,87,89,90,90,91]
#x=np.array([-0.04773042,-0.54508323,0.85572,0.44027,-
0.26309,-
0.877323,0.33,0.22,0.47,0.65,0.77,0.99,0.24,0.66,0.99,0.77,0.1
0,0.55])
pl.hist(x,bins=20,color='m',histtype='barstacked')
pl.xlabel("Ages")
pl.ylabel("Frequency")
pl.title("Histogram of Ages")
pl.show()
plt.hist(ages,bins,range,color='green',histtype='bar',rwidth=0.8)
plt.xlabel('age')
plt.ylabel('No of people')
plt.title('My histogram')
plt.show()
# create a histogram for the following test scores :
[99,97,94,88,84,81,80,77,71,25]
#x=np.array([-0.04773042,-0.54508323,0.85572,0.44027,-
0.26309,-
0.877323,0.33,0.22,0.47,0.65,0.77,0.99,0.24,0.66,0.99,0.77,0.1
0,0.55])
weight=[78,72,69,81,63,67,65,75,79,74,71,83,71,79,80,69]
plt.hist(weight,cumulative='True',orientation='vertical',histtype
='barstacked')
plt.title("Simple Histogram")
plt.show()
# 1D Array
array = np.random.randn(10)
print("1D Array filled with random values : \n", array);
plt.hist(array)
plt.show()
a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])
plt.hist(a, bins = [0,10,20,30,40,50,60,70,80,90,100])
plt.title("histogram")
plt.show()
"""