Matplotlib
English translation
Learning objectives
The same numbers reveal different relationships depending on the graph. Distinguish changes over time from comparisons across categories.
Graphs Suited to the Representation
Starting conditions
, temperature=[20,21,23,22,24] °C.
Procedure
- Display the same data as a line plot and a bar chart.
- Use actual values to explain which representation makes trends or values at specific times easier to read.
Results to retain
- 2 plots and 3 sentences explaining the choice of representation.
import numpy as np
import matplotlib.pyplot as plt
t=np.arange(5);temp=np.array([20,21,23,22,24])
plt.plot(t,temp,'o-');plt.xlabel('Time [s]');plt.ylabel('Temperature [C]');plt.grid()
Record results and self-check
Representation:
Observed facts:
Times and values used:
Suitable purpose:
Points to check
- Did you display axis titles, units, and ticks?
Comparing Two Measurements
Starting conditions
Add the second sensor's data [19,21,22,23,23] and compare on the same axes.
Procedure
- Associate the second sensor values
[19,21,22,23,23]with the same times , and plot them on the same axes in the same Figure as the first sensor. - Use a legend to distinguish the two sensors. Record time, first sensor value, second sensor value, and first minus second in five rows.
- Find and explain the times when the two sensors agree and differ most, using the table and plots.
Results to retain
- Time plots of both sensors and a table comparing values at the same times.
temp2=np.array([19,21,22,23,23])
Record results and self-check
Time:
First sensor value:
Second sensor value:
First − second value:
Points to check
- Did you compare the two sensors' values at matching times?
Checking Other Inputs
Starting conditions
Plot the same two sensors' data as a scatter plot, and compare interpretations when time order is removed.
Procedure
- Pair the two sensors' values at each time and create a scatter plot with the first sensor on the x-axis and the second on the y-axis. Use the same data as the preceding time plot.
- Label each point with its time to identify the sample. Explain the relationship between the two sensors visible in the scatter plot separately from the sequence of changes that cannot be inferred without time labels.
Results to retain
- Compare interpretations of a sensor-value scatter plot labeled with times and a time plot.
# Use the preceding activity's data and functions to check the specified new examples.
Record results and self-check
The two scatter plot axes:
Correspondence between times and points:
Visible relationship between the two sensors:
Interpretation of changes over time:
Points to check
- Can you map scatter plot points back to their original times?