ML#03 - Matplotlib 3
ML#03 - Matplotlib 3
pyplot as plt
import numpy as np
import pandas as pd
In [2]: #1. Write a Python program to plot two or more lines on same plot with suitable legends
<matplotlib.legend.Legend at 0x2d814877a20>
Out[2]:
In #2. Write a Python program to plot two or more lines with legends, different widths and
[3]:
x1 =np.array ([10, 20, 30])
x2 =np.array ([10, 20, 30])
y1 = np.array([20, 40, 10])
y2= np.array ([40,10, 30]) plt.xlabel ("x-axis") plt.ylabel ("y-axis")
plt.plot(x1,y1, color= "blue", linewidth = 3) plt.plot( x2, y2, color = "red", linewidth =5)
plt.legend(["Line 1 width =3", "Line 2 width = 5"],loc = "upper right")
<matplotlib.legend.Legend at 0x2d81493c5f8>
Out[3]:
In [4]: # Write a Python programming to display a bar chart of the popularity of programming
Lan
x= ['Java', 'Python',' PHP', 'JavaScript', 'C#', 'C+
+'] y= [22.2, 17.6, 8.8, 8, 7.7, 6.7]
plt.bar( x,y, color="blue")
plt.xlabel(" Programming Languages")
plt.ylabel ("Popularity")
plt.title ("Popularity of programming languages worldwide, Oct 2017 compared to a year
a
plt.minorticks_on()
plt.grid(which='major', linestyle='-', linewidth='0.5', color='red')
plt.grid(which='minor', linestyle=':', linewidth='0.5', color='black')
In [5]: #3. Write a Python program to draw a scatter plot comparing two subject marks
of #Mathematics and Science. Use marks of 10 students.
math_marks = [88, 92, 80, 89, 100, 80, 60, 100, 80, 34]
science_marks = [35, 79, 79, 48, 100, 88, 32, 45, 20, 30]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
plt.show()
In [13]: #4. Write a Python programming to create a pie chart of the popularity
of #programming Languages.
# Data
programming_languages = ['Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C+
+'] Popularity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
explode = (0.1, 0, 0, 0, 0, 0) # Explode the second slice (Python)
plt.show()
In [ ]: