Untitled
unknown
plain_text
2 years ago
691 B
6
Indexable
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()
Editor is loading...