Challenge - 5 Problems
Plot Customization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the size of the plot created by this code?
Consider this code that creates a plot with pandas. What is the size of the figure in inches?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = {'A': [1, 3, 2, 4]} df = pd.DataFrame(data) ax = df.plot(figsize=(8, 4)) plt.close() # Close plot to avoid display
Attempts:
2 left
💡 Hint
The figsize parameter expects a tuple (width, height) in inches.
✗ Incorrect
The figsize argument sets the width and height of the plot in inches. Here, figsize=(8, 4) means width=8 inches and height=4 inches.
❓ Predict Output
intermediate2:00remaining
What is the title of the plot after running this code?
This code creates a plot and sets a title. What will be the exact title shown on the plot?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = {'B': [5, 2, 7, 1]} df = pd.DataFrame(data) ax = df.plot() ax.set_title('Sales Over Time') plt.close()
Attempts:
2 left
💡 Hint
Titles are case sensitive and appear exactly as set.
✗ Incorrect
The set_title method sets the plot title exactly as the string provided, including capitalization.
❓ data_output
advanced2:00remaining
What are the x and y axis labels after this code runs?
This code sets labels for x and y axes. What are the labels shown on the plot axes?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = {'C': [10, 20, 15, 25]} df = pd.DataFrame(data) ax = df.plot() ax.set_xlabel('Month') ax.set_ylabel('Revenue') plt.close()
Attempts:
2 left
💡 Hint
Labels are set exactly by set_xlabel and set_ylabel methods.
✗ Incorrect
The x-axis label is set to 'Month' and the y-axis label to 'Revenue' by the respective methods.
❓ visualization
advanced2:00remaining
Which option shows the correct plot title and axis labels after this code?
This code creates a plot with a title and axis labels. Which option correctly describes the plot's title and labels?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = {'D': [3, 6, 9, 12]} df = pd.DataFrame(data) ax = df.plot(figsize=(5, 3)) ax.set_title('Quarterly Growth') ax.set_xlabel('Quarter') ax.set_ylabel('Growth (%)') plt.close()
Attempts:
2 left
💡 Hint
Check the exact strings used in set_title, set_xlabel, and set_ylabel.
✗ Incorrect
The title and labels are exactly as set in the code: 'Quarterly Growth', 'Quarter', and 'Growth (%)'.
🔧 Debug
expert2:00remaining
What error does this code raise when trying to set the plot size?
This code tries to set the figure size but causes an error. What is the error type?
Pandas
import pandas as pd import matplotlib.pyplot as plt data = {'E': [1, 2, 3, 4]} df = pd.DataFrame(data) ax = df.plot(figsize=[6, 4]) plt.close()
Attempts:
2 left
💡 Hint
Check if figsize accepts list or tuple.
✗ Incorrect
The figsize parameter accepts both tuples and lists, so no error occurs.