# Visualising scientific computation

Physics I · Computer Science · https://tryals.app/learn/physics-i/visualising-scientific-computation

## Visualising Scientific Data

Visualisation turns raw computational output into physical insight, revealing patterns that flat numbers hide.

```python
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 2*np.pi, 200)
plt.plot(t, np.sin(t), label="sin(t)")
plt.xlabel("Time (s)"); plt.ylabel("Amplitude")
plt.legend(); plt.grid(True); plt.show()
```

**Essential plot types for physics**

| Plot | Use Case |
| --- | --- |
| **Line plot** | Time series, trajectories |
| **Scatter** | Experimental data points |
| **Histogram** | Measurement distributions |
| **Contour** | 2D scalar fields |
| **Vector** | Force / velocity fields |

## Best Practices & Pitfalls

A clear plot communicates science cleanly, while bad practices distort the truth.

- Always label axes with **units**.
- Use a **legend** for multiple series.
- Add **error bars**: `plt.errorbar(x, y, yerr=err)`.
- Save as vector (`.pdf`) for publications.

**Common Pitfall:** Axis choices manufacture or hide stories. Truncated y-axes exaggerate trends, and log scales linearise exponentials. Always read the axes before believing any plot.

## Practice questions

6 of this lesson's 14 practice questions, with answers. The full set is in the app.

### 1. Complete the statement with the correct term.

**Answer:** A plot of data points as (x, y) pairs with no connecting lines is called a **scatter** plot.

**Why:** Scatter plots display individual data points without connecting them.

Page: https://tryals.app/practice/physics-i/visualising-scientific-computation/complete-the-statement-with-the-correct-term

### 2. Match each chart type to its best use case.

**Answer:**

- Line plot → Showing a trend over time
- Scatter plot → Revealing correlation between two variables
- Histogram → Displaying frequency distribution
- Pie chart → Showing parts of a whole

**Why:** Choosing the right chart type makes data easier to interpret.

Page: https://tryals.app/practice/physics-i/visualising-scientific-computation/match-each-chart-type-to-its-best-use-case

### 3. Order the steps to create a scientific plot from raw data.

**Answer:**

1. Load the dataset from a file
2. Clean and preprocess the data
3. Choose the appropriate chart type
4. Add axis labels, title, and legend

**Why:** Proper plotting starts with data preparation and ends with clear labelling.

Page: https://tryals.app/practice/physics-i/visualising-scientific-computation/order-the-steps-to-create-a-scientific-plot-from-raw-data

### 4. You simulate a pendulum and plot angle vs. time, the curve looks like a clean cosine, but its amplitude **slowly grows** each swing. Energy should be conserved. What did the plot most likely just catch?

A. A correct depiction of resonance with gravity
B. The pendulum genuinely gains energy from friction
C. Numerical error pumping energy into the system
D. A plotting-library rendering artifact

**Answer:** C. Numerical error pumping energy into the system

**Why:** The plot is a conservation-law audit: growing amplitude reveals the integrator (likely explicit Euler) injecting energy. This is why physicists plot conserved quantities as sanity checks, and why orbital simulations use symplectic integrators that respect energy by construction.

Page: https://tryals.app/practice/physics-i/visualising-scientific-computation/you-simulate-a-pendulum-and-plot-angle-vs-time-the-curve-looks-like

### 5. Match each dataset to the plot type that reveals its story best.

**Answer:**

- Temperature sampled every minute for a day → Line plot vs. time
- Height vs. weight for 500 people → Scatter plot
- Distribution of 1000 measurement errors → Histogram
- Energy budget split into categories → Bar chart

**Why:** Plot choice is question choice: lines for evolution, scatters for correlation, histograms for distribution, bars for comparison. The right plot makes the conclusion visible before any statistics are computed.

Page: https://tryals.app/practice/physics-i/visualising-scientific-computation/match-each-dataset-to-the-plot-type-that-reveals-its-story-best

### 6. A histogram and a bar chart are exactly the same type of plot.

**Answer:** False

**Why:** A histogram shows the distribution of a continuous variable using bins; a bar chart compares discrete categories.

Page: https://tryals.app/practice/physics-i/visualising-scientific-computation/a-histogram-and-a-bar-chart-are-exactly-the-same-type-of-plot
