0
0
Matplotlibdata~20 mins

Alpha transparency for overlap in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Alpha Transparency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the effect of alpha in this scatter plot?
Consider this code that plots two overlapping scatter plots with different alpha values. What will be the visual effect of setting alpha=0.3 for the second plot?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y1 = [5, 4, 3, 2, 1]
y2 = y1
plt.scatter(x, y1, color='blue', label='Set 1')
plt.scatter(x, y2, color='red', alpha=0.3, label='Set 2')
plt.legend()
plt.show()
AThe red points will be semi-transparent, allowing the blue points to be visible underneath where they overlap.
BThe red points will appear brighter than the blue points because of alpha=0.3.
CThe red points will be invisible because alpha=0.3 means fully transparent.
DThe red points will be fully opaque and hide the blue points underneath.
Attempts:
2 left
💡 Hint
Alpha controls transparency from 0 (invisible) to 1 (fully visible).
data_output
intermediate
1:30remaining
How many points are visible after applying alpha transparency?
Given two overlapping scatter plots each with 5 points, where the second plot uses alpha=0.5, how many points will be visible in the final plot?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y1 = [5, 4, 3, 2, 1]
y2 = y1
plt.scatter(x, y1, color='green', label='Set 1')
plt.scatter(x, y2, color='orange', alpha=0.5, label='Set 2')
plt.legend()
plt.show()

visible_points = len(x) * 2
A10
B5
C0
D7
Attempts:
2 left
💡 Hint
Alpha affects transparency, not the number of points drawn.
🔧 Debug
advanced
2:30remaining
Why does this plot not show transparency?
This code tries to plot two overlapping histograms with alpha=0.5, but the transparency effect is not visible. What is the cause?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data1 = np.random.normal(0, 1, 1000)
data2 = np.random.normal(0, 1, 1000)

plt.hist([data1, data2], bins=30, color=['blue', 'red'], alpha=0.5)
plt.show()
AThe histograms overlap exactly and matplotlib stacks them by default, hiding transparency.
BThe histograms are plotted with default stacking, so the second hides the first completely.
CAlpha=0.5 is too high to see transparency in histograms.
DThe code is missing plt.show() to display transparency.
Attempts:
2 left
💡 Hint
Check how matplotlib handles overlapping histograms by default.
visualization
advanced
2:00remaining
Which plot shows correct alpha blending for overlapping areas?
You have two overlapping scatter plots with alpha=0.4 and alpha=0.6 respectively. Which plot correctly shows the combined color intensity in overlapping areas?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

x = np.random.rand(50)
y = np.random.rand(50)

plt.scatter(x, y, color='purple', alpha=0.4, label='Set 1')
plt.scatter(x, y, color='yellow', alpha=0.6, label='Set 2')
plt.legend()
plt.show()
AThe overlapping area appears only yellow because alpha=0.6 is higher than 0.4.
BThe overlapping area appears white because colors add up to full brightness.
CThe overlapping area appears only purple because alpha=0.4 is lower than 0.6.
DThe overlapping area appears as a mix of purple and yellow with medium brightness.
Attempts:
2 left
💡 Hint
Alpha blending mixes colors based on transparency levels.
🧠 Conceptual
expert
1:30remaining
Why use alpha transparency in data visualization?
Which of the following is the best reason to use alpha transparency when plotting overlapping data points?
ATo increase the contrast between plot elements and background.
BTo reduce the file size of the saved plot image.
CTo make overlapping points visible by showing density through transparency.
DTo change the color of points automatically based on their value.
Attempts:
2 left
💡 Hint
Think about how transparency helps when many points overlap.