import matplotlib.pyplot #import matplotlib.pyplot as plt #creating lists mpg = [21 , 21 , 22.8 , 21.4 , 18.7 , 18.1 , 14.3 , 24.4 , 22.8 , 19.2 , 17.8 , 16.4 , 17.3 , 15.2 , 10.4 , 10.4 , 14.7 , 32.4 , 30.4 , 33.9 , 21.5 , 15.5 , 15.2 , 13.3 , 19.2 , 27.3 , 26 , 30.4 , 15.8 , 19.7 , 15 , 21.4] wt = [2.62 , 2.875 , 2.32 , 3.215 , 3.44 , 3.46 , 3.57 , 3.19 , 3.15 , 3.44 , 3.44 , 4.07 , 3.73 , 3.78 , 5.25 , 5.424 , 5.345 , 2.2 , 1.615 , 1.835 , 2.465 , 3.52 , 3.435 , 3.84 , 3.845 , 1.935 , 2.14 , 1.513 , 3.17 , 2.77 , 3.57 , 2.78] mpg wt # create scatter plot matplotlib.pyplot.scatter(mpg,wt) # Use short cut to create scatter plot plt.scatter(mpg,wt) # change colour with "c" plt.scatter(mpg,wt, c= "red") #ed7c31 orange #0273bf blue # change size with "s" plt.scatter(mpg,wt, c= "red",s=50) # change axis limit plt.scatter(mpg,wt, c= "red",s=50) plt.xlim(10,40) plt.ylim(0,6) # line chart EB = [6 , 0 , 2 , 1 , 2 , 1 , 2 , 2 , 2 , 0 , 1 , 3 , 0 , 3 , 1 , 0 , 4 , 1 , 3 , 3 , 6 , 2 , 0 , 0 , 4 , 1 , 2 , 1 , 1 , 0 , 1 , 3 , 0 , 1 , 1 , 1 , 3 , 1 , 3 , 0 , 2 , 2 , 2 , 1 , 2 , 2 , 1 , 2 , 1 , 2 , 1 , 2 , 4 , 0 , 1 , 1 , 2 , 2 , 2 , 0 , 2 , 2 , 0 , 0 , 2 , 3 , 2 , 2 , 3 , 0 , 3 , 3 , 0 , 1 , 0 , 0 , 2 , 1 , 1 , 3 , 1 , 3 , 1 , 1 , 0 , 2 , 0 , 3 , 3 , 3 , 2 , 0 , 0 , 1 , 4 , 1 , 0 , 2 , 1 , 1 , 2 , 2 , 0 , 2 , 1 , 1 , 2 , 3 , 1 , 4 , 4 , 1 , 2 , 2 , 2 , 1 , 0 , 0 , 5 , 1 , 1 , 1 , 0 , 1 , 1 , 0 , 2 , 1 , 3 , 2 , 1 , 1 , 1 , 0 , 1 , 1 , 3 , 2 , 1 , 3 , 1 , 2 , 1 , 1 ] EB MB = [0 , 2 , 1 , 0 , 0 , 1 , 1 , 1 , 2 , 2 , 0 , 1 , 2 , 1 , 0 , 0 , 4 , 2 , 0 , 1 , 0 , 1 , 4 , 0 , 1 , 3 , 0 , 1 , 0 , 2 , 5 , 0 , 0 , 1 , 3 , 2 , 1 , 0 , 3 , 1 , 3 , 0 , 1 , 1 , 1 , 1 , 1 , 2 , 0 , 0 , 2 , 0 , 0 , 0 , 1 , 1 , 2 , 1 , 1 , 0 , 1 , 1 , 1 , 3 , 0 , 1 , 1 , 1 , 3 , 3 , 1 , 0 , 0 , 3 , 2 , 0 , 0 , 3 , 2 , 0 , 0 , 0 , 1 , 0 , 3 , 5 , 2 , 2 , 1 , 1 , 3 , 0 , 1 , 0 , 2 , 2 , 1 , 2 , 2 , 4 , 1 , 1 , 0 , 2 , 1 , 1 , 1 , 1 , 3 , 1 , 0 , 1 , 1 , 1 , 3 , 1 , 2 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 2 , 0 , 1 , 0 , 1 , 1 , 0 , 1 , 2 , 1 , 0 , 1 , 2 , 0 , 1 , 0 , 1 , 2 ] MB import matplotlib.pyplot as plt # create line chart plt.plot(EB) # create line chart plt.plot(EB) plt.plot(MB) plt.xlim(0,145) # change the colour to brown & show seperately plt.plot(EB, c="brown")#new code plt.show()#new code plt.plot(MB) plt.xlim(0,145) # put Title with title keyword plt.plot(EB, c="brown") plt.title("Plot no. 1")#new code plt.show() plt.plot(MB) plt.title("Plot no. 2")#new code plt.xlim(0,145) # Label on x axis and y axis plt.plot(EB, c="brown") plt.title("Plot no. 1") plt.plot(MB) plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code # Ticks plt.plot(EB, c="brown") plt.title("Plot no. 1") plt.plot(MB) plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.xticks([0,60,100,140],["Bad","Avg","Good","super",])#new code # rotation of text plt.plot(EB, c="brown") plt.title("Plot no. 1") plt.plot(MB) plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.xticks([0,60,100,140],["Bad","Avg","Good","super",], rotation = 90)#new code # line style with ls plt.plot(EB, c="brown", ls="--")#new code plt.title("Plot no. 1") plt.plot(MB) plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.xticks([0,60,100,140],["Bad","Avg","Good","super",], rotation = 90) # Annotate plt.plot(EB, c="brown") plt.title("Plot no. 1") plt.plot(MB) plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.annotate("Max value", xy=(20,6), xytext=(70,6), arrowprops=dict(facecolor="magenta"))#new code # figure size with plt.figure plt.figure(figsize=(10,5))#new code plt.plot(EB, c="brown") plt.title("Plot no. 1") plt.plot(MB) plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.annotate("Max value", xy=(20,6), xytext=(70,6), arrowprops=dict(facecolor="magenta")) # legend with label & legend plt.figure(figsize=(10,5)) plt.plot(EB, c="brown", label="East Bengal")#new code plt.title("Plot no. 1") plt.plot(MB, label="mohun Bagan")#new code plt.legend()#new code plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.annotate("Max value", xy=(20,6), xytext=(70,6), arrowprops=dict(facecolor="magenta")) # legend location plt.figure(figsize=(10,5)) plt.plot(EB, c="brown", label="East Bengal") plt.title("Plot no. 1") plt.plot(MB, label="mohun Bagan") plt.legend(loc = "upper right")#upper left/lower right #new code plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.annotate("Max value", xy=(20,6), xytext=(70,6), arrowprops=dict(facecolor="magenta")) # save the figure plt.figure(figsize=(10,5)) plt.plot(EB, c="brown", label="East Bengal") plt.title("Plot no. 1") plt.plot(MB, label="mohun Bagan") plt.legend(loc = "upper right")#upper left/lower right #new code plt.xlim(0,145) plt.xlabel("Matches Played")#new code plt.ylabel("Goals scored")#new code plt.annotate("Max value", xy=(20,6), xytext=(70,6), arrowprops=dict(facecolor="magenta")) plt.savefig( "C:/Users/Desktop/python plot/Line chart.pdf") #.jpeg or .png # we can create histogram with hist keyword plt.hist(EB) # We will add bins - different discrete values plt.hist(EB, bins=range(8)) # We will add figsize and legends plt.figure(figsize=(8,5))#figure size plt.hist(EB, bins=range(8), label="East Bengal") plt.legend()#legends # We will add figsize and legends plt.figure(figsize=(8,5)) plt.hist(EB, bins=range(8), label="East Bengal") plt.legend() plt.xlim(0,7)#removes the extra white space plt.xlabel("Goals scored")#x axis name plt.ylabel("No of Goals")#y axis name # We may plot goals of EB & MB in same chart plt.figure(figsize=(8,5)) plt.hist((EB,MB), bins=range(8), color=["red","green"],#add colors label=["East Bengal","Mohun Bagan"]) plt.legend() plt.xlim(0,7)#removes the extra white space plt.xlabel("Goals scored")#x axis name plt.ylabel("No of Goals")#y axis name