0
0
Matplotlibdata~10 mins

Bubble charts concept in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a basic bubble chart using matplotlib.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
sizes = [100, 200, 300, 400]
plt.scatter(x, y, s=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Asizes
Bx
Cy
Dplt
Attempts:
3 left
💡 Hint
Common Mistakes
Using x or y instead of sizes for the bubble size parameter.
Forgetting to pass the sizes list to the s parameter.
2fill in blank
medium

Complete the code to add colors to the bubbles in the chart.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
sizes = [100, 200, 300, 400]
colors = ['red', 'blue', 'green', 'purple']
plt.scatter(x, y, s=sizes, c=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Asizes
Bx
Ccolors
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Passing sizes or coordinates instead of colors to the c parameter.
Not passing any colors, resulting in default colors.
3fill in blank
hard

Fix the error in the code to correctly display the bubble chart with labels.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
sizes = [100, 200, 300, 400]
labels = ['A', 'B', 'C', 'D']
plt.scatter(x, y, s=sizes)
for i, label in enumerate(labels):
    plt.text(x[i], y[i], [1])
plt.show()
Drag options to blanks, or click blank then click option'
Alabel
Blabels[i]
Clabels
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using labels[i] instead of label inside the loop.
Using labels which is the whole list, not a single label.
4fill in blank
hard

Fill both blanks to create a bubble chart with transparency and a title.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
sizes = [100, 200, 300, 400]
plt.scatter(x, y, s=sizes, alpha=[1])
plt.[2]('My Bubble Chart')
plt.show()
Drag options to blanks, or click blank then click option'
A0.5
B0.8
Ctitle
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using xlabel instead of title for the plot title.
Setting alpha to a value greater than 1 or less than 0.
5fill in blank
hard

Fill all three blanks to create a bubble chart with edge colors, a grid, and axis labels.

Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
sizes = [100, 200, 300, 400]
plt.scatter(x, y, s=sizes, edgecolors=[1])
plt.grid([2])
plt.xlabel([3])
plt.show()
Drag options to blanks, or click blank then click option'
A'black'
BTrue
C'X Axis'
D'none'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'none' for edgecolors which removes edges.
Passing False to plt.grid which hides the grid.
Not passing a string to plt.xlabel.