Matplotlib (1 6)
Matplotlib (1 6)
ipynb - Colaboratory
days = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature = [36.6, 37, 37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
plt.plot(days, temperature)
plt.show()
output
days = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature = [36.6, 37, 37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
# plot line with x-axis, y-axis and title
plt.plot(days, temperature)
plt.title("Delhi Temperature")
plt.xlabel("days")
plt.ylabel("temperature")
plt.show()
days = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature = [36.6, 37, 37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
# plot line with x-axis, y-axis and title
plt.plot(days, temperature)
plt.axis([0,30, 0,50]) # set axis
plt.title("Delhi Temperature")
plt.xlabel("days")
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 1/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
plt.ylabel("temperature")
plt.show()
days = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature = [36.6, 37, 37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
# plot line with x-axis, y-axis and title
plt.plot(days, temperature, color = "g", marker = "o", linestyle= ":",
linewidth = 2, markersize = 10)
plt.title("Delhi Temperature")
plt.xlabel("days")
plt.ylabel("temperature")
plt.show()
days = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature = [36.6, 37, 37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
from matplotlib import style # import style module
style.use("ggplot") # give ggplot parameter value to use() method
plt.plot(days, temperature, "mo--", linewidth = 3,
markersize = 10, label = "Temp line")
plt.title("Delhi Temperature", fontsize=15)
plt.xlabel("days",fontsize=13)
plt.ylabel("temperature",fontsize=13)
plt.legend(loc = 4)
plt.grid()
plt.show()
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 2/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
days = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
temperature = [36.6, 37, 37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
from matplotlib import style # import style module
style.use("ggplot") # give ggplot parameter value to use() method
plt.plot(days, temperature, "mo--", linewidth = 3,
markersize = 10, label = "Temp line")
plt.title("Delhi Temperature", fontsize=15)
plt.xlabel("days",fontsize=13)
plt.ylabel("temperature",fontsize=13)
plt.legend(loc = 4)
plt.grid(color='c', linestyle='-', linewidth=2)
plt.show()
days = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
delhi_tem = [36.6, 37, 37.7,39,40.1,43,43.4,45,45.6,40.1,44,45,46.8,47,47.8]
mumbai_tem = [39,39.4,40,40.7,41,42.5,43.5,44,44.9,44,45,45.1,46,47,46]
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 3/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
Ploting Histograms
print(ml_students_age)
print(py_students_age)
[29 33 36 26 28 28 33 34 26 33 29 39 18 20 27 30 43 26 38 40 41 29 27 41
26 21 42 24 39 38 24 26 38 24 29 34 28 43 39 21 33 35 21 44 20 44 27 35
18 28 35 43 19 31 38 41 42 43 35 43 19 33 18 19 24 31 43 34 37 40 18 23
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 4/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
27 37 25 19 31 32 34 41 39 40 24 41 42 25 39 42 25 42 28 28 37 25 29 29
41 41 27 27]
[33 21 33 30 16 28 19 28 36 30 25 18 15 24 39 32 21 36 19 39 37 16 31 39
17 20 32 31 24 32 33 27 16 34 34 21 27 18 39 35 28 38 23 29 27 28 36 17
29 22 19 28 31 21 32 20 39 15 22 17 24 20 30 33 33 31 24 18 36 16 27 18
26 32 28 31 20 20 33 22 31 26 21 39 33 23 24 39 33 17 39 27 19 16 21 26
22 26 22 19]
plt.hist(ml_students_age)
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 5/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 6/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
# Dataset of 'Indian Artificial Intelligence Production (IAIP) Class"
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 7/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
style.use("ggplot")
plt.figure(figsize=(16,9)) # figure size with ratio 16:9
plt.bar(classes, class1_students, width = 0.6, align = "edge", color = "k",
edgecolor = "m", linewidth = 5, alpha = 0.9, linestyle = "--",
label =" Class 1 Students") #visible=False
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 8/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
plt.figure(figsize=(16,9))
plt.barh(classes, class1_students, align = "edge", color = "k",
edgecolor = "m", linewidth = 5, alpha = 0.9, linestyle = "--",
label =" Class 1 Students") #visible=False
plt.figure(figsize=(16,9))
plt.bar(classes, class1_students, width = 0.6, align = "edge", color = "k",
edgecolor = "m", linewidth = 5, alpha = 0.9, linestyle = "--",
label =" Class 1 Students") #visible=False
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 9/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
plt.figure(figsize=(16,9))
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 10/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
The above code not generating two bar charts in one figure but they are overlapping. So use the below code to plot multiple bar charts. In below
chart plot three bar charts using three different datasets.
plt.figure(figsize=(16,9))
classes_index = np.arange(len(classes))
width = 0.2
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 11/13
10/24/23, 7:46 PM Untitled9.ipynb - Colaboratory
plt.figure(figsize=(16,9))
classes_index = np.arange(len(classes))
width = 0.2
https://colab.research.google.com/drive/1Fqc3o0NSdZP8rNbezsHx94OSnwy7EDCO?authuser=0#scrollTo=WgmacUIG9Xvl&printMode=true 12/13