Statement of Completion#5c4c8986
Visualizations with Matplotlib
easy
When Is It Wrong to Use Scatter or Line Plots?
Resolution
Activities
Import libraries¶
In [1]:
import matplotlib.pyplot as plt
import pandas as pd
Activities¶
1. Scatter Plots with Non-Numerical Data¶
In [2]:
# Dummy data
data = {
'Category': ['A', 'B', 'C', 'D'],
'Value': [10, 20, 30, 40]
}
df = pd.DataFrame(data)
Do not change the labels of the axes and the title of the plot.
In [3]:
fig, ax = plt.subplots()
# Your code here
ax.scatter(df['Category'], df['Value'])
ax.set_xlabel('Category')
ax.set_ylabel('Value')
ax.set_title('Scatter Plot with Categorical Data')
# Display the plot
plt.show()
2. Does the scatter plot effectively communicate any meaningful relationship or pattern?¶
In [ ]:
# Select the correct option
3. Line Plots for Unordered Categories¶
In [5]:
# Sample unordered categorical data
data = {
'Category': ['Type A', 'Type C', 'Type B', 'Type D'],
'Value': [15, 35, 25, 45]
}
df = pd.DataFrame(data).sort_values('Category')
Do not change the labels of the axes and the title of the plot.
In [6]:
fig, ax = plt.subplots()
# Your code here (create a plot)
ax.plot(df['Category'], df['Value'])
ax.set_xlabel('Category')
ax.set_ylabel('Value')
ax.set_title('Line Plot with Unordered Categorical Data')
# Display the plot
plt.show()
4. Which of the following statements best reflects the suitability of using a scatter plot for time series data?¶
In [8]:
# Sample time series data
dates = pd.date_range(start='2021-01-01', periods=5, freq='D')
data = {'Date': dates, 'Value': [10, 15, 14, 17, 16]}
df = pd.DataFrame(data)
In [9]:
# Creating a scatter plot
plt.scatter(df['Date'], df['Value'])
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('Scatter Plot with Time Series Data')
plt.show()