-
Notifications
You must be signed in to change notification settings - Fork 16
/
solution_62.py
61 lines (43 loc) · 1.99 KB
/
solution_62.py
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
import matplotlib.pyplot as plt
time = [0, 1.85, 2.87, 3.78, 4.65, 5.50, 6.31, 7.14, 7.96, 8.79, 9.69]
distance = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
velocity = [0, 5.41, 9.80, 10.99, 11.49, 11.76, 12.35, 12.05, 12.20, 12.05, 11.11]
acceleration = [0, 2.92, 4.30, 1.31, 0.57, 0.32, 0.73, -0.36, 0.18, -0.18, -1.04]
# Solution using procedural mode
# ******************************
# Adjust plot size to make it bigger than the default.
plt.figure(figsize=(10, 5))
# Create a new plot with the distance, velocity and acceleration vs. time data.
plt.plot(time, distance, '--s', label='distance [m]', markersize=5)
plt.plot(time, velocity, '-o', label='velocity [m/s]', color='teal', markersize=5)
plt.plot(time, acceleration, '--', label='acceleration [m/s^2]', color='darkorange')
# Add X and Y axis labels.
plt.xlabel('Time [s]')
plt.ylabel('Distance [m]')
# Set a title and a legend for the figure.
# Note the use of the "fontsize" and "markerscale" arguments to adjust
# the size of the legend.
plt.title('Usain Bold 100m gold medal sprint - Beijing 2008')
plt.legend(fontsize=12, markerscale=1.2)
# Display the figure.
plt.show()
# Solution using object-oriented mode
# ***********************************
# Create a new figure object, adjust the size.
fig = plt.figure(figsize=(10, 5))
# Create an axis object (a subplot). Add the distance, velocity and
# acceleration vs. time data.
ax = fig.add_subplot()
ax.plot(time, distance, '--s', label='distance [m]', markersize=5)
ax.plot(time, velocity, '-o', label='velocity [m/s]', color='teal', markersize=5)
ax.plot(time, acceleration, '--', label='acceleration [m/s^2]', color='darkorange')
# Add X and Y axis labels.
ax.set_xlabel('Time [s]')
ax.set_ylabel('Distance [m]')
# Set a title and a legend for the figure.
# Note the use of the "fontsize" and "markerscale" arguments to adjust
# the size of the legend.
ax.set_title('Usain Bold 100m gold medal sprint - Beijing 2008')
ax.legend(fontsize=12, markerscale=1.2)
# Display the figure.
plt.show()