0
0
Matplotlibdata~10 mins

Violin plot with plt.violinplot 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 violin plot of the data list.

Matplotlib
import matplotlib.pyplot as plt

data = [1, 2, 3, 4, 5, 6, 7]
plt.[1](data)
plt.show()
Drag options to blanks, or click blank then click option'
Aviolinplot
Bboxplot
Chist
Dscatter
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.boxplot instead of plt.violinplot.
Using plt.hist which creates a histogram, not a violin plot.
2fill in blank
medium

Complete the code to add a title to the violin plot.

Matplotlib
import matplotlib.pyplot as plt

data = [5, 10, 15, 20, 25]
plt.violinplot(data)
plt.[1]('My Violin Plot')
plt.show()
Drag options to blanks, or click blank then click option'
Axlabel
Btitle
Clegend
Dylabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.xlabel or plt.ylabel instead of plt.title.
Trying to add a legend when there is only one data set.
3fill in blank
hard

Fix the error in the code to correctly plot multiple violin plots for two data sets.

Matplotlib
import matplotlib.pyplot as plt

data1 = [1, 2, 3, 4, 5]
data2 = [2, 3, 4, 5, 6]
plt.violinplot([1])
plt.show()
Drag options to blanks, or click blank then click option'
A[data1, data2]
Bdata1, data2
Cdata1 + data2
D[data1]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data1 and data2 as separate arguments instead of a list.
Concatenating the lists which merges data instead of plotting separately.
4fill in blank
hard

Fill both blanks to create a violin plot with custom positions and show the plot.

Matplotlib
import matplotlib.pyplot as plt

data = [[1, 2, 3], [4, 5, 6]]
plt.violinplot(data, positions=[1])
plt.[2]()
Drag options to blanks, or click blank then click option'
A[1, 2]
Bshow
Cplot
D[0, 1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect positions that don't match data sets.
Forgetting to call plt.show() to display the plot.
5fill in blank
hard

Fill all three blanks to create a violin plot with custom widths, show means, and display the plot.

Matplotlib
import matplotlib.pyplot as plt

data = [3, 5, 7, 9, 11]
plt.violinplot(data, widths=[1], showmeans=[2])
plt.[3]()
Drag options to blanks, or click blank then click option'
A0.5
BTrue
Cshow
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using showmeans=False which hides the mean marker.
Forgetting to call plt.show() to display the plot.
Using invalid width values like strings.