Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
691 B
2
Indexable
Never
import pandas as pd
import matplotlib.pyplot as plt

# Load data
cars = pd.read_csv('cars.csv')

# Create a figure with subplots
fig, ax = plt.subplots(figsize=(50, 80))

# Create a boxplot with all data
cars.boxplot(column='Hwy MPG', by='Cyl', ax=ax, widths=0.5)

# Group data by cylinder size and create a box plot for each group
groups = cars.groupby('Cyl')
for idx, (name, group) in enumerate(groups):
    group.boxplot(column='Hwy MPG', positions=[name], ax=ax, widths=0.5)
    plt.title('Box Plot for {} Cylinder Cars'.format(name))
    plt.xlabel('Cylinders')
    plt.ylabel('Miles per Gallon')
    plt.xticks(rotation=45)

plt.savefig("all_BP.png")
plt.show()