0% found this document useful (0 votes)
11 views3 pages

Session 8 Lecture 1

Uploaded by

darayir140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Session 8 Lecture 1

Uploaded by

darayir140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

In [ ]:

1 import matplotlib.pyplot as plt


2
3 x = ["MATHS", "SCIENCE", "ENGLISH", "HINDI"]
4 y = [49, 35, 41, 31]
5
6 plt.bar(x, y, color='g')
7 # You can use plt.yticks
8 #plt.yticks(range(0, 101, 10))
9 plt.show()

In [ ]:

1 plt.barh(x, y)
2 plt.show()

In [ ]:

1 plt.bar(x, y, width = 0.5)


2 plt.show()

Legends
Plot legends give meaning to a visualization.
In [50]:

1 import matplotlib.pyplot as plt


2 x = [x for x in range(0,11)]
3 y = [2*x for x in x]
4
5 plt.figure(dpi=150)
6 plt.plot(x, y, c='b', marker='^', label = '$2x$')
7
8 y2 = [x**2 for x in x]
9
10 plt.plot(x[0:3], y2[0:3], c='r')
11 plt.plot(x[2:], y2[2:], c='r', ls='--', marker='o', label='$x^2$')
12
13 plt.xlabel('X Axis')
14 plt.ylabel('Y Axis')
15
16 plt.xticks(range(0,11))
17 plt.yticks(range(0,101, 10))
18
19 plt.grid()
20
21 plt.title("Legend Example")
22 plt.legend(fancybox=True, framealpha=True, shadow=True, borderpad=1)
23
24 plt.show()

Pie Chart
In [3]:

1 import matplotlib.pyplot as plt


2
3 #plt.figure(dpi=100)
4
5 y = [35, 25, 25, 20, 15, 10, 4]
6
7 mylabels = ["A", "B", "C", "D", "E", "F", "G"]
8 #plt.pie(y, labels = mylabels, autopct='%.2f%%')
9
10 myexplode = [0.1, 0.1, 0.1, 0.1, 0.1, 0.3, 0.3]
11 plt.pie(y, labels = mylabels, explode = myexplode,
12 shadow = True, autopct='%.2f%%', counterclock=False,
13 radius = 2, startangle=90)
14
15 plt.title("Fruits", loc="left")
16 #plt.legend(title='Fruits',loc='upper left')
17 plt.show()

You might also like