0
0
Matplotlibdata~10 mins

Before-after comparison plots 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 import the plotting library needed for before-after comparison plots.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Anumpy
Bseaborn
Cpandas
Dmatplotlib.pyplot
Attempts:
3 left
💡 Hint
Common Mistakes
Importing numpy or pandas instead of matplotlib.pyplot.
Using seaborn without importing matplotlib.pyplot.
2fill in blank
medium

Complete the code to create a figure and axis for plotting before-after data.

Matplotlib
fig, [1] = plt.subplots()
Drag options to blanks, or click blank then click option'
Afigure
Baxis
Cplot
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'figure' as the second variable instead of 'axis'.
Using 'plot' or 'data' which are not returned by subplots.
3fill in blank
hard

Fix the error in the code to plot before and after values as connected points.

Matplotlib
axis.plot(['Before', 'After'], [before_value, after_value], marker=[1])
Drag options to blanks, or click blank then click option'
Ao
B'x'
C'o'
D'marker'
Attempts:
3 left
💡 Hint
Common Mistakes
Using marker without quotes causing a NameError.
Using an invalid marker string.
4fill in blank
hard

Fill both blanks to add labels and a title to the before-after plot.

Matplotlib
axis.set_xlabel([1])
axis.set_title([2])
Drag options to blanks, or click blank then click option'
A'Time Point'
B'Value Change'
C'Before and After Comparison'
D'Measurement'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the label and title texts.
Using unrelated labels or titles.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each time point to its value if the value increased.

Matplotlib
result = [1]: [2] for [3] in ['Before', 'After'] if values[[3]] > values['Before']
Drag options to blanks, or click blank then click option'
A'time'
Bvalues[time]
Ctime
D'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of variables for keys or values.
Using incorrect variable names.