0
0
Matplotlibdata~20 mins

Bubble charts concept in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bubble Chart Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Bubble Chart Size Scaling
What will be the size of the bubbles in the plot generated by the following code snippet?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
sizes = [10, 20, 30]
plt.scatter(x, y, s=sizes)
plt.show()
print(sizes)
A[100, 400, 900]
B[10, 20, 30]
C[1, 2, 3]
D[10, 20, 30, 40]
Attempts:
2 left
💡 Hint
The 's' parameter in plt.scatter controls the area of each bubble, not the radius.
data_output
intermediate
2:00remaining
Number of Bubbles Displayed
Given the following data and code, how many bubbles will appear in the bubble chart?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 30, 40]
sizes = [15, 25, 35]
plt.scatter(x, y, s=sizes)
plt.show()
ARaises ValueError
B4
C3
D0
Attempts:
2 left
💡 Hint
The lengths of x, y, and sizes must match for plt.scatter.
visualization
advanced
2:30remaining
Interpreting Bubble Chart Colors and Sizes
Consider this code that creates a bubble chart with color and size representing different data aspects. What does the color represent in the resulting plot?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np
x = np.array([5, 15, 25, 35, 45])
y = np.array([10, 20, 30, 40, 50])
sizes = np.array([100, 200, 300, 400, 500])
colors = np.array([1, 2, 3, 4, 5])
plt.scatter(x, y, s=sizes, c=colors, cmap='viridis')
plt.colorbar()
plt.show()
AThe colors represent the sizes of the bubbles.
BThe colors represent the x-axis values.
CThe colors are randomly assigned and do not represent any data.
DThe colors represent the values in the 'colors' array, mapped to the 'viridis' color scale.
Attempts:
2 left
💡 Hint
The 'c' parameter controls color mapping in plt.scatter.
🔧 Debug
advanced
2:00remaining
Identify the Error in Bubble Chart Code
What error will this code produce when run?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5]
sizes = [10, 20, 30]
plt.scatter(x, y, s=sizes)
plt.show()
AValueError: x and y must be the same size
BTypeError: sizes must be a scalar or array-like
CIndexError: list index out of range
DNo error, plot displays correctly
Attempts:
2 left
💡 Hint
Check if x and y have the same number of elements.
🚀 Application
expert
3:00remaining
Choosing Bubble Sizes for Visual Clarity
You have data points with values ranging from 1 to 1000. You want to create a bubble chart where bubble sizes reflect these values but remain visually clear and not too large. Which approach is best to set the bubble sizes?
AUse the raw values directly as sizes in plt.scatter.
BUse the logarithm (base 10) of the values as sizes without scaling.
CApply a square root transformation to the values before passing as sizes.
DNormalize values between 0 and 1 and use them directly as sizes.
Attempts:
2 left
💡 Hint
Bubble area grows with the size parameter, so large raw values can cause huge bubbles.