1.4 Visualizing Archaeological Data: Bar Charts and Scatterplots
Objective: Learn to create basic visualizations using matplotlib and pandas
In previous chapters, you learned how to structure, filter, and clean archaeological datasets. Now, we move to the next step: making data visible. In this chapter, you’ll use Python libraries matplotlib
and pandas
to build simple charts that help you and others better understand patterns in archaeological data.
We continue working with our fictional excavation site, Tell Logika, where you’ll visualize metal tool adoption and compare site-level excavation data. You’ll explore how different trenches reveal different distributions when visualized as bar charts or scatterplots.
1.4.1 Why Visualize Data?
- Visualizations reveal patterns and trends
- They help us understand comparisons and outliers
- Charts communicate results clearly to others
As archaeologists, we often deal with complex and layered data — counts of artifacts by type, comparisons across time periods, or material presence by site. Visualizations turn abstract data into intuitive visuals that tell a story.
1.4.2 Python Visualization Tools
- matplotlib.pyplot: Customizable, low-level plotting tool
- pandas.DataFrame.plot(): Simple, high-level charting using structured data
We’ll start with matplotlib
to build a bar chart and scatterplot, then show how pandas
simplifies charting when your data is already organized.
1.4.3 Bar Chart – Metal Tool Use by Trench
import matplotlib.pyplot as plt
metal_use = {"TL01": 75, "TL02": 40, "TL03": 85}
plt.bar(metal_use.keys(), metal_use.values())
plt.title("Metal Tool Use by Trench")
plt.xlabel("Trench ID")
plt.ylabel("% Metal Tools")
plt.grid(True)
plt.show()
Bar charts help compare categories — in this case, the percentage of metal tools found in each trench. You can immediately see which areas had higher metal adoption.
1.4.4 Scatterplot – Site Elevation vs Metal Tool Use
elevation = [150, 160, 200] # in meters
metal_use = [40, 75, 85]
sites = ["TL02", "TL01", "TL03"]
plt.scatter(elevation, metal_use)
for i, site in enumerate(sites):
plt.text(elevation[i], metal_use[i], site)
plt.title("Elevation vs Metal Tool Use")
plt.xlabel("Elevation (m)")
plt.ylabel("% Metal Tools")
plt.grid(True)
plt.show()
Scatterplots reveal relationships. This chart lets you ask: Do higher elevation sites show more metal tool usage? You can see this more clearly when plotted.
🔁 Try switching axes for a different perspective:
If you’d prefer to display elevation on the Y-axis (higher elevations appear higher in the chart), you can flip the axes. This helps visually emphasize elevation as a vertical dimension, which can be more intuitive.
# Flip the axes: metal use on X, elevation on Y
plt.scatter(metal_use, elevation)
for i, site in enumerate(sites):
plt.text(metal_use[i], elevation[i], site)
plt.title("Metal Tool Use vs Elevation")
plt.xlabel("% Metal Tools")
plt.ylabel("Elevation (m)")
plt.grid(True)
plt.show()
This variation keeps the same data but shifts how we interpret it. Use whichever layout communicates your message more clearly.
1.4.5 Quick Plotting with pandas
import pandas as pd
df = pd.DataFrame({
"Trench": ["TL01", "TL02", "TL03"],
"Metal_Tools": [75, 40, 85]
})
df.plot(x="Trench", y="Metal_Tools", kind="bar", legend=False)
plt.title("Metal Tool Use by Trench (pandas)")
plt.ylabel("% Metal Tools")
plt.grid(True)
plt.show()
Once your data is in a DataFrame, pandas
lets you create visuals with one line of code. It’s ideal for fast exploration and prototyping.
1.4.6 Basic Plot Customization
- Add titles and axis labels
- Use annotations to label points clearly
- Apply gridlines for readability
Simple visual touches go a long way toward clarity. Always include titles and labels to help your viewer quickly understand your visual story.
1.4.7 Which Chart Type Should You Use?
Purpose | Chart Type |
---|---|
Compare categories | Bar chart |
Show relationships | Scatterplot |
Display change over time | Line chart |
Show parts of a whole | Pie chart |
1.4.8 Now It’s Your Turn!
Let’s apply your knowledge with an exercise from Tell Logika.
📊 Activity: Visualizing Tool Use at Tell Logika
Scenario: Your archaeological team has collected data on metal tool use and site elevation across three trenches at Tell Logika. You need to present this data visually to help identify patterns in metal tool distribution.
Instructions:
- Create a new folder:
ComputationalArchaeology
- Create a subfolder:
chapter1
- Create a Jupyter notebook named:
Visualizing_Tools.ipynb
Use the following starter code:
import matplotlib.pyplot as plt
import pandas as pd
# Bar chart: metal use by trench
metal_use = {"TL01": 75, "TL02": 40, "TL03": 85}
plt.bar(metal_use.keys(), metal_use.values())
plt.title("Metal Tool Use by Trench")
plt.xlabel("Trench ID")
plt.ylabel("% Metal Tools")
plt.grid(True)
plt.show()
# Scatterplot: elevation vs metal use
elevation = [150, 160, 200]
metal_use = [40, 75, 85]
sites = ["TL02", "TL01", "TL03"]
plt.scatter(elevation, metal_use)
for i, site in enumerate(sites):
plt.text(elevation[i], metal_use[i], site)
plt.title("Elevation vs Metal Tool Use")
plt.xlabel("Elevation (m)")
plt.ylabel("% Metal Tools")
plt.grid(True)
plt.show()
# pandas bar chart
df = pd.DataFrame({
"Trench": ["TL01", "TL02", "TL03"],
"Metal_Tools": [75, 40, 85]
})
df.plot(x="Trench", y="Metal_Tools", kind="bar", legend=False)
plt.title("Metal Tool Use by Trench (pandas)")
plt.ylabel("% Metal Tools")
plt.grid(True)
plt.show()
Tips:
- Change trench IDs or add more data to test chart flexibility
- Modify gridlines, labels, or chart colors
- Use
plt.savefig("filename.png")
to export your charts
1.4.9 Quick Review
- ✅ Use
plt.bar()
for comparing trench categories - ✅ Use
plt.scatter()
for visualizing relationships like elevation vs tool use - ✅ Use
pandas.plot()
for quick DataFrame visuals - ✅ Always label your axes and title your charts