Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions 02_activities/assignments/participation/session_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Visualization— Live Learning Session 1
Date: 2026-01-15

Overview:
- Learned how to create a basic figure using matplotlib.
- Generated small sample data using NumPy.
- Created a simple scatter plot and confirmed it renders correctly.

Notes / takeaways:
- Using a fixed random seed helps make plots reproducible (same random values each run).
- plt.subplots() is a clean way to create a Figure + Axes object for plotting.
- Scatter plots are useful for showing relationships/patterns between two numeric variables.
"""

import numpy as np
import matplotlib.pyplot as plt

# --- Create sample data (reproducible) ---
np.random.seed(613)
x = np.arange(50)
y = np.random.randint(0, 100, 50)

# --- Make a basic scatter plot ---
fig, ax = plt.subplots(figsize=(5, 3))
ax.scatter(x, y)

# Add minimal labeling for readability
ax.set_title("Basic scatter plot (Session 1)")
ax.set_xlabel("x (index)")
ax.set_ylabel("y (random integer 0–100)")

plt.tight_layout()
plt.show()
40 changes: 40 additions & 0 deletions 02_activities/assignments/participation/session_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Visualization — Live Learning Session 2
Date: 2026-01-20

Overview:
- This session focused on understanding good and bad data visualization.
- We discussed how visualization choices depend on purpose audience and context.
- Examples were shown to compare effective and ineffective chart designs.

Notes:
- A good visualization makes the message easy to understand.
- A bad visualization increases confusion or can mislead the viewer.
- Design choices such as chart type labels color and scale matter.
- Bar charts are usually better for comparing values than pie charts.
- Too many colors effects or decorations reduce clarity.
- Accessibility includes readable labels good contrast and not relying only on color.
"""

import numpy as np
import matplotlib.pyplot as plt

# Sample data used to demonstrate different visualization choices
categories = ["A", "B", "C", "D", "E"]
values = [25, 40, 55, 30, 45]

# Clear example: bar chart
fig, ax = plt.subplots(figsize=(6, 3))
ax.bar(categories, values)
ax.set_title("Bar chart example")
ax.set_xlabel("Category")
ax.set_ylabel("Value")
plt.tight_layout()
plt.show()

# Less effective example: pie chart for comparison
fig, ax = plt.subplots(figsize=(5, 4))
ax.pie(values, labels=categories, autopct="%1.0f%%")
ax.set_title("Pie chart example")
plt.tight_layout()
plt.show()
50 changes: 50 additions & 0 deletions 02_activities/assignments/participation/session_03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Visualization — Live Learning Session 3
Date: 2026-01-22

Overview:
- This session focused on reproducible data visualization.
- We reviewed how visualizations communicate and persuade and how they reflect choices.
- We practiced making plots with multiple series and improving readability with labels legends and annotations.
- We also practiced removing tick marks and labels when they are not needed.

Notes:
- Reproducibility means someone else can run the same code and get the same results.
- Using a fixed random seed helps keep generated example data consistent.
- Visualizations are not neutral because we choose what to show and how to show it.
- Adding labels and a legend makes it easier to interpret multiple series.
- Annotations can highlight an important value or point in the plot.
- Removing ticks or tick labels can reduce clutter if they do not add meaning.
"""

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import NullFormatter
from matplotlib.ticker import NullLocator

np.random.seed(613)
x = np.arange(50)
y1 = np.random.randint(0, 100, 50)
y2 = np.random.randint(0, 100, 50)

fig, ax = plt.subplots(figsize=(5, 3))

ax.scatter(x, y1, label="Person 1")
ax.scatter(x, y2, label="Person 2")
ax.legend(loc="lower right")

ax.text(
10,
95,
"This value is important!",
ha="center",
color="red",
fontsize=14
)

ax.yaxis.set_major_locator(NullLocator())
ax.xaxis.set_major_formatter(NullFormatter())

ax.set_title("Reproducible scatter plot example")
plt.tight_layout()
plt.show()
67 changes: 67 additions & 0 deletions 02_activities/assignments/participation/session_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Session 04: Visualization with purpose and accessible data visualization

This session focused on designing visualizations with a clear purpose
and applying accessibility principles so that visualizations are usable
by a wide audience.

Key ideas:
- Visualizations should be created with a specific audience and goal in mind
- Design choices are not neutral and affect interpretation
- Accessibility should be considered from the start
"""

# Import required libraries
import numpy as np
import matplotlib.pyplot as plt

# -----------------------------
# Reproducible data generation
# -----------------------------
# Set a random seed so results can be reproduced
np.random.seed(42)

x = np.arange(50)
y1 = np.random.randint(0, 100, 50)
y2 = np.random.randint(0, 100, 50)

# -----------------------------
# Create a visualization with purpose
# -----------------------------
# Purpose: compare two groups clearly on the same axes

fig, ax = plt.subplots(figsize=(6, 4))

ax.scatter(x, y1, label="Group 1")
ax.scatter(x, y2, label="Group 2")

ax.set_title("Comparison of Two Groups Over Time")
ax.set_xlabel("Observation Index")
ax.set_ylabel("Value")

ax.legend(loc="lower right")

# -----------------------------
# Accessibility considerations
# -----------------------------
# - Clear labels and title
# - Legend included instead of relying only on color
# - Reasonable figure size for readability

# Add a short annotation to guide interpretation
ax.annotate(
"Higher values indicate increased measurements",
xy=(5, 90),
ha="left"
)

plt.tight_layout()
plt.show()

"""
Notes:
- The visualization communicates a clear message rather than showing data without context
- Labels and legends reduce reliance on color alone
- A fixed random seed supports reproducibility
- Simple annotations help guide the viewer
"""
85 changes: 85 additions & 0 deletions 02_activities/assignments/participation/session_05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""
Session 5 (260129) Participation
Topic: Subplots and combining visualizations plus wrapping up remaining coding topics

Key ideas
- Use subplots to compare views side by side when it supports the message
- Use layout tools so labels and titles do not overlap
- Save figures with a stable file name for reproducibility
- Combine plot types in one figure when the relationship is meaningful
- Reminder from class: check paths and dependencies early when running scripts
"""

import numpy as np
import matplotlib.pyplot as plt


np.random.seed(42)

x = np.arange(50)
y_line = np.random.randint(10, 80, size=50)

names = ["Luffy", "Zoro", "Nami", "Usopp", "Sanji"]
scores = [110, 180, 240, 100, 220]

fig, ax = plt.subplots(figsize=(7, 3))
ax.plot(x, y_line)
ax.set_title("Line chart example")
ax.set_xlabel("Index")
ax.set_ylabel("Value")
fig.tight_layout()
plt.show()


fig, ax = plt.subplots(figsize=(7, 3))
ax.bar(names, scores)
ax.set_title("Bar chart example")
ax.set_xlabel("Character")
ax.set_ylabel("Score")
fig.tight_layout()
plt.show()


fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 4))

axes[0].scatter(x, y_line)
axes[0].set_title("Scatter view")
axes[0].set_xlabel("Index")
axes[0].set_ylabel("Value")

axes[1].bar(names, scores)
axes[1].set_title("Bar view")
axes[1].set_xlabel("Character")
axes[1].set_ylabel("Score")

fig.tight_layout()
plt.show()


layout = [["A", "B"], ["C", "C"]]
fig, axd = plt.subplot_mosaic(layout, figsize=(10, 6), constrained_layout=True)

axd["A"].scatter(x, y_line)
axd["A"].set_title("A: Scatter")

axd["B"].plot(x, y_line)
axd["B"].set_title("B: Line")

axd["C"].bar(names, scores)
axd["C"].set_title("C: Bar (wide)")

plt.show()


fig, ax = plt.subplots(figsize=(7, 3))
ax.plot(x, y_line)
ax.set_title("Saving a figure")
ax.set_xlabel("Index")
ax.set_ylabel("Value")
fig.tight_layout()

output_path = "session_05_saved_plot.png"
fig.savefig(output_path, dpi=300)
plt.show()

print(f"Saved figure to: {output_path}")