0
0
Data Analysis Pythondata~20 mins

Styling and themes in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Styling and Themes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this seaborn plot style code?
Consider the following Python code using seaborn and matplotlib to set a style and plot a simple line chart. What style is applied to the plot background?
Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_style('darkgrid')
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()
AThe plot has a white background with grid lines.
BThe plot has a dark background with grid lines.
CThe plot has a white background without grid lines.
DThe plot has a dark background without grid lines.
Attempts:
2 left
💡 Hint
Check seaborn's documentation for the 'darkgrid' style description.
data_output
intermediate
2:00remaining
What is the color of bars in this matplotlib bar chart with a custom style?
Given this code snippet, what color will the bars be in the resulting bar chart?
Data Analysis Python
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.bar(['A', 'B', 'C'], [5, 7, 3])
plt.show()
ABlue bars with white grid lines.
BRed bars with gray grid lines.
CGray bars with white grid lines.
DGreen bars with white grid lines.
Attempts:
2 left
💡 Hint
The 'ggplot' style uses a gray color palette for bars.
visualization
advanced
2:30remaining
Which option produces a seaborn heatmap with the 'white' style applied?
You want to create a heatmap with a white background and no grid lines using seaborn. Which code snippet correctly applies the 'white' style before plotting?
Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(5,5)
A
sns.set_style('dark')
sns.heatmap(data)
plt.show()
B
sns.set_style('white')
sns.heatmap(data)
plt.show()
C
sns.set_style('whitegrid')
sns.heatmap(data)
plt.show()
D
sns.set_style('ticks')
sns.heatmap(data)
plt.show()
Attempts:
2 left
💡 Hint
The 'white' style removes grid lines and sets a white background.
🧠 Conceptual
advanced
2:30remaining
What does the matplotlib style context manager do?
What is the effect of using matplotlib's style.context in this code snippet?
Data Analysis Python
import matplotlib.pyplot as plt
with plt.style.context('seaborn-dark'):
    plt.plot([1, 2, 3], [3, 2, 1])
    plt.show()
plt.plot([1, 2, 3], [1, 2, 3])
plt.show()
ABoth plots use the 'seaborn-dark' style.
BNeither plot uses the 'seaborn-dark' style.
COnly the second plot uses the 'seaborn-dark' style; the first uses default style.
DOnly the first plot uses the 'seaborn-dark' style; the second uses default style.
Attempts:
2 left
💡 Hint
The style.context applies style only inside the with block.
🔧 Debug
expert
3:00remaining
Why does this seaborn style setting not change the plot appearance?
This code tries to set a seaborn style but the plot looks unchanged. What is the reason?
Data Analysis Python
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style('darkgrid')
plt.style.use('classic')
plt.plot([1, 2, 3], [3, 2, 1])
plt.show()
Aplt.style.use('classic') overrides sns.set_style('darkgrid'), so the plot uses 'classic' style.
Bsns.set_style('darkgrid') overrides plt.style.use('classic'), so the plot uses 'darkgrid' style.
CBoth styles combine, resulting in a mixed style plot.
DNeither style is applied because they conflict, so default style is used.
Attempts:
2 left
💡 Hint
The last style setting before plotting takes effect.