Bird
Raised Fist0
Matplotlibdata~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the alpha parameter control in a matplotlib plot?
easy
A. The size of plot elements
B. The color of plot elements
C. The shape of plot elements
D. The transparency level of plot elements

Solution

  1. Step 1: Understand the role of alpha in plotting

    The alpha parameter sets how transparent or see-through a plot element is.
  2. Step 2: Compare with other visual properties

    Color changes hue, size changes dimension, shape changes form, but only alpha controls transparency.
  3. Final Answer:

    The transparency level of plot elements -> Option D
  4. Quick Check:

    Alpha = transparency [OK]
Hint: Alpha means transparency from 0 (clear) to 1 (solid) [OK]
Common Mistakes:
  • Confusing alpha with color
  • Thinking alpha changes size
  • Assuming alpha changes shape
2. Which of the following is the correct way to set alpha transparency to 0.5 in a matplotlib scatter plot?
easy
A. plt.scatter(x, y, alpha=0.5)
B. plt.scatter(x, y, transparency=0.5)
C. plt.scatter(x, y, opacity=0.5)
D. plt.scatter(x, y, alpha=5)

Solution

  1. Step 1: Recall the correct parameter name for transparency

    Matplotlib uses alpha to set transparency, not transparency or opacity.
  2. Step 2: Check the value range for alpha

    Alpha values must be between 0 and 1, so 0.5 is valid, but 5 is not.
  3. Final Answer:

    plt.scatter(x, y, alpha=0.5) -> Option A
  4. Quick Check:

    Alpha param and value 0.5 [OK]
Hint: Use alpha=0.5 for half transparency in matplotlib [OK]
Common Mistakes:
  • Using wrong parameter names like transparency or opacity
  • Setting alpha value outside 0-1 range
  • Confusing alpha with color or size
3. What will be the effect of this code snippet on the plot?
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y1 = [1, 4, 9, 16]
y2 = [2, 3, 5, 7]
plt.plot(x, y1, alpha=0.3)
plt.plot(x, y2, alpha=0.7)
plt.show()
medium
A. The second line will be invisible
B. Both lines will have the same transparency
C. The first line will be more transparent than the second
D. The first line will be solid and the second transparent

Solution

  1. Step 1: Understand alpha values in the code

    The first plot line uses alpha=0.3, which means it is 30% opaque (70% transparent). The second uses alpha=0.7, which is 70% opaque.
  2. Step 2: Compare transparency levels

    Lower alpha means more transparent, so the first line is more see-through than the second.
  3. Final Answer:

    The first line will be more transparent than the second -> Option C
  4. Quick Check:

    Lower alpha = more transparent [OK]
Hint: Lower alpha means more see-through, higher means more solid [OK]
Common Mistakes:
  • Thinking higher alpha means more transparent
  • Assuming alpha affects color, not transparency
  • Confusing which line has which alpha
4. Identify the error in this code that tries to set alpha transparency for overlapping scatter points:
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y, alpha='0.5')
plt.show()
medium
A. Alpha parameter is not valid for scatter plots
B. Alpha value should be a float, not a string
C. x and y lists must be numpy arrays
D. Missing plt.figure() before plotting

Solution

  1. Step 1: Check the alpha parameter type

    Alpha expects a numeric float between 0 and 1, but here it is passed as a string '0.5'.
  2. Step 2: Understand matplotlib type requirements

    Passing alpha as a string will cause a TypeError or unexpected behavior.
  3. Final Answer:

    Alpha value should be a float, not a string -> Option B
  4. Quick Check:

    Alpha must be float, not string [OK]
Hint: Alpha must be a number, not text, for transparency [OK]
Common Mistakes:
  • Passing alpha as a string instead of float
  • Thinking alpha is invalid for scatter plots
  • Assuming lists must be numpy arrays
5. You have two overlapping histograms plotted with:
plt.hist(data1, bins=20, alpha=0.4)
plt.hist(data2, bins=20, alpha=0.6)

How would you adjust alpha values to better see where the two datasets overlap clearly?
hard
A. Set both alphas to 0.5 for balanced transparency
B. Set alpha of data1 to 1 and data2 to 0 for full visibility
C. Set both alphas to 1 to make histograms solid
D. Set alpha of data1 to 0 and data2 to 0.5 to hide data1

Solution

  1. Step 1: Understand the goal of alpha in overlapping plots

    Alpha helps see overlapping areas by making plots semi-transparent.
  2. Step 2: Balance transparency for both datasets

    Setting both alphas to 0.5 makes both histograms equally transparent, so overlaps are visible clearly.
  3. Step 3: Evaluate other options

    Setting alpha to 1 or 0 hides or fully shows one dataset, losing overlap clarity.
  4. Final Answer:

    Set both alphas to 0.5 for balanced transparency -> Option A
  5. Quick Check:

    Equal alpha ~ balanced overlap visibility [OK]
Hint: Use equal moderate alpha for clear overlap visibility [OK]
Common Mistakes:
  • Making one histogram fully opaque and the other invisible
  • Using alpha=1 which hides overlap
  • Setting alpha=0 hides data completely
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard