7. outline
about
body
graph
conclude
exercise
Bar Graph
Code:
import numpy as np
import matplotlib.pyplot as plt
objects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')
y_pos = np.arange(len(objects))
performance = [10, 8, 6, 4, 2, 1]
plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.xlabel('Objects')
plt.ylabel('Usage')
plt.title('Programming language usage')
8. outline
about
body
graph
conclude
exercise
4 plots in Single Graph
Plot x, -x, sin(x), xsin(x), in range -5pie to 5pie
Add a legend, Annotate the origin, Set axis limit to the range of X
Code:
import numpy as np
import matplotlib.pyplot as plt
x= np.linspace(-5*np.pi, 5*np.pi, 500)
plt.plot(x, x, 'b')
plt.plot(x, -x, 'b')
plt.plot(x, np.sin(x), 'g', linewidth=2)
plt.plot(x, x*np.sin(x), 'r', linewidth=3)
plt.xlabel('x axis-->')
plt.ylabel('y axis-->')
plt.legend(['x', '-x', 'sin(x)', 'xsin(x)'])
plt.annotate('origin', xy=(0,0))
plt.xlim(-5*np.pi, 5*np.pi)
plt.ylim(-5*np.pi, 5*np.pi)
9. outline
about
body
graph
conclude
exercise
MCQ Question
How will you set X and Y axis limit of a plot so that the region of
the interest is in the rectangle (0,-1.5) (bottom left co-ordinate)
and (2*pi,1.5) (right top co-ordinate)
a) Xlim(0, 2*pi)
Ylim(-1.5, 1.5)
b) Xlim(0, -1.5)
Ylim(2*pi, 1.5)
c) Xlim(2*pi, 0)
Ylim(1.5, -1.5)
d) Xlim(-1.5, 1.5)
Ylim(0, 2*pi)
Notes de l'éditeur
For maths and for plotting graph ---plot x,y using defalt line style and colour