You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Box plot for the Revs Per Mile for the Audi, Hyundai, Suzuki, and Toyota car manufacturers.
importpandasaspdimportmatplotlib.pyplotaspltimportseabornassns# Load datadf=pd.read_csv('Cars93.csv')
df1=df[df['Manufacturer'].isin(['Audi', 'Hyundai', 'Suzuki', 'Toyota'])]
# Create a boxplot with filled colorsplt.figure(figsize=(12, 6))
box=df1.boxplot(column='Rev.per.mile', by='Manufacturer', patch_artist=True)
plt.title('Boxplot of Rev Per Mile by Manufacturer')
plt.suptitle('') # Remove the default title to avoid overlapplt.xlabel('Manufacturer')
plt.ylabel('Rev.per.mile')
plt.show()
<Figure size 1200x600 with 0 Axes>
The boxplot indicates that Toyota achieves the highest revolutions per mile.
2. Histograms of MPG in the city and MPG on the highway.
# Create histogramsplt.figure(figsize=(12, 6))
# Create histograms on the same axisplt.figure(figsize=(12, 6))
plt.hist(df['MPG.highway'], bins=10, color='blue', alpha=0.7, label='MPG.highway')
plt.hist(df['MPG.city'], bins=10, color='orange', alpha=0.7, label='MPG.city')
plt.title('Histograms of MPG.highway and MPG.city')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.legend()
plt.show()
<Figure size 1200x600 with 0 Axes>
The histograms indicate that MPG Highway (blue) typically demonstrates greater fuel efficiency compared to MPG City (orange).
3. Line plot of Wheelbase vs Turning Circle
# Create a line plotdf=df.sort_values('Wheelbase')
plt.figure(figsize=(10, 6))
plt.plot(df['Wheelbase'], df['Turn.circle'], marker='o', linestyle='-')
plt.title('Turn.circle vs Wheelbase')
plt.xlabel('Wheelbase')
plt.ylabel('Turn.circle')
plt.grid(True)
plt.show()
The line plot illustrates that the turning circle is directly related to the wheelbase.
4. Bar Chart of average horsepower for different car types.
# Load your datadf=pd.read_csv('Cars93.csv')
# Group by car type and calculate the average horsepoweraverage_horsepower=df.groupby('Type')['Horsepower'].mean()
# Create a bar chartplt.figure(figsize=(12, 6))
bars=plt.bar(average_horsepower.index, average_horsepower, color='skyblue')
# Add values on the barsforbarinbars:
yval=bar.get_height()
plt.text(bar.get_x() +bar.get_width()/2, yval, round(yval, 2), ha='center', va='bottom')
plt.title('Average Horsepower by Car Type')
plt.xlabel('Car Type')
plt.ylabel('Average Horsepower')
plt.xticks(rotation=45)
plt.grid(axis='y', linestyle='--', linewidth=0.7)
plt.show()
The bar chart shows large car type has the highest average horsepower (179.45).