-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph.py
More file actions
110 lines (91 loc) · 2.69 KB
/
graph.py
File metadata and controls
110 lines (91 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import matplotlib.pyplot as plt
import numpy as np
# 1. Plot of y = x^3
x1 = np.linspace(-5, 5, 100)
y1 = x1**3
plt.figure(figsize=(12, 8))
plt.subplot(231) # Subplot for y = x^3
plt.plot(x1, y1, label='y = x^3')
plt.xlabel('x')
plt.ylabel('y')
plt.title('y = x^3')
plt.legend()
# 2. Plot of sin(x) and cos(x)
x2 = np.linspace(0, 2 * np.pi, 100)
y2_sin = np.sin(x2)
y2_cos = np.cos(x2)
plt.subplot(232) # Subplot for sin(x) and cos(x)
plt.plot(x2, y2_sin, label='sin(x)')
plt.plot(x2, y2_cos, label='cos(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.title('sin(x) and cos(x)')
plt.legend()
# 3. Plot of tan(x) and cot(x)
x3 = np.linspace(-1.5 * np.pi, 1.5 * np.pi, 100)
y3_tan = np.tan(x3)
y3_cot = 1 / np.tan(x3)
plt.subplot(233) # Subplot for tan(x) and cot(x)
plt.plot(x3, y3_tan, label='tan(x)')
plt.plot(x3, y3_cot, label='cot(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.title('tan(x) and cot(x)')
plt.legend()
# 4. Plot of y = x^2 and y = x^3
x4 = np.linspace(-5, 5, 100)
y4_x2 = x4**2
y4_x3 = x4**3
plt.subplot(234) # Subplot for y = x^2 and y = x^3
plt.plot(x4, y4_x2, label='y = x^2')
plt.plot(x4, y4_x3, label='y = x^3')
plt.xlabel('x')
plt.ylabel('y')
plt.title('y = x^2 and y = x^3')
plt.legend()
# 5. Plot of y = x^2 and y = x^3 with a legend
plt.subplot(235)
plt.plot(x4, y4_x2, label='y = x^2')
plt.plot(x4, y4_x3, label='y = x^3')
plt.xlabel('x')
plt.ylabel('y')
plt.title('y = x^2 and y = x^3')
plt.legend()
# 6. Plot of y = x^2 and y = x^3 with a legend and a title
plt.subplot(236)
plt.plot(x4, y4_x2, label='y = x^2')
plt.plot(x4, y4_x3, label='y = x^3')
plt.xlabel('x')
plt.ylabel('y')
plt.title('y = x^2 and y = x^3')
plt.legend()
# 7. Plot of y = x^2 and y = x^3 on the same plot with a legend, title, and axis labels
x7 = np.linspace(-5, 5, 100)
y7_x2 = x7**2
y7_x3 = x7**3
plt.figure(figsize=(12, 4))
plt.subplot(131)
plt.plot(x7, y7_x2, label='y = x^2', color='blue')
plt.plot(x7, y7_x3, label='y = x^3', color='green')
plt.xlabel('x')
plt.ylabel('y')
plt.title('y = x^2 and y = x^3')
plt.legend()
# 8. Plot of y = x^2 and y = x^3 on the same plot with a legend, title, axis labels, and different colors
plt.subplot(132)
plt.plot(x7, y7_x2, label='y = x^2', color='red')
plt.plot(x7, y7_x3, label='y = x^3', color='purple')
plt.xlabel('x')
plt.ylabel('y')
plt.title('y = x^2 and y = x^3')
plt.legend()
# 9. Scatter plot of y = x^2 and y = x^3 on the same plot with a legend, title, axis labels, different colors, and different markers
plt.subplot(133)
plt.scatter(x7, y7_x2, label='y = x^2', color='orange', marker='o')
plt.scatter(x7, y7_x3, label='y = x^3', color='brown', marker='x')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Scatter Plot: y = x^2 and y = x^3')
plt.legend()
plt.tight_layout()
plt.show()