0
0
Data Analysis Pythondata~10 mins

Line plots in Data Analysis Python - 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 simple line plot using matplotlib.

Data Analysis Python
import matplotlib.pyplot as plt

data = [1, 3, 2, 5, 7]
plt.[1](data)
plt.show()
Drag options to blanks, or click blank then click option'
Ascatter
Bplot
Cbar
Dhist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' instead of 'plot' which creates a scatter plot.
Using 'bar' which creates bar charts, not line plots.
2fill in blank
medium

Complete the code to add labels to the x-axis and y-axis of the line plot.

Data Analysis Python
import matplotlib.pyplot as plt

data = [2, 4, 6, 8]
plt.plot(data)
plt.xlabel([1])
plt.ylabel('Value')
plt.show()
Drag options to blanks, or click blank then click option'
A'Time'
BValue
C'X-axis'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the label text.
Using the wrong label that does not describe the x-axis.
3fill in blank
hard

Fix the error in the code to correctly plot two lines on the same graph.

Data Analysis Python
import matplotlib.pyplot as plt

x = [1, 2, 3]
y1 = [2, 4, 6]
y2 = [1, 3, 5]
plt.plot(x, y1)
plt.plot(x, [1])
plt.show()
Drag options to blanks, or click blank then click option'
Ay2
By1
Cx
D[1, 2, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the first y-values list twice.
Using x instead of y-values for the second plot.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Data Analysis Python
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the word variable in the condition instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if length is greater than 3.

Data Analysis Python
words = ['data', 'science', 'is', 'fun']
lengths = { [1]: [2] for word in words if [3] }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Clen(word) > 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting words to uppercase for keys.
Using the word itself as the value instead of its length.
Incorrect condition in the if clause.