import matplotlib.pyplot as plt # Sample data categories = ['A', 'B', 'C', 'D'] values = [10, 15, 7, 20] plt.bar(categories, values, color='blue') plt.xlabel('Categories') plt.ylabel('Values') plt.title('Basic Bar Plot') plt.show()
import matplotlib.pyplot as plt import numpy as np # Sample data categories = ['A', 'B', 'C', 'D'] values1 = [10, 15, 7, 20] values2 = [12, 18, 6, 15] x = np.arange(len(categories)) width = 0.35 fig, ax = plt.subplots() bars1 = ax.bar(x - width/2, values1, width, label='Group 1') bars2 = ax.bar(x + width/2, values2, width, label='Group 2') ax.set_xlabel('Categories') ax.set_ylabel('Values') ax.set_title('Grouped Bar Plot') ax.set_xticks(x) ax.set_xticklabels(categories) ax.legend() plt.show()
import matplotlib.pyplot as plt # Sample data categories = ['A', 'B', 'C', 'D'] values1 = [10, 15, 7, 20] values2 = [12, 18, 6, 15] fig, ax = plt.subplots() bars1 = ax.bar(categories, values1, label='Group 1') bars2 = ax.bar(categories, values2, bottom=values1, label='Group 2') ax.set_xlabel('Categories') ax.set_ylabel('Values') ax.set_title('Stacked Bar Plot') ax.legend() plt.show()
import matplotlib.pyplot as plt # Sample data with car models only categories = [ 'Toyota Camry', 'Honda Accord', 'Tesla Model 3', 'Ford F-150', 'Chevrolet Silverado', 'BMW 3 Series', 'Mercedes-Benz C-Class', 'Jeep Wrangler', 'Subaru Outback', 'Hyundai Sonata' ] values = [45, 38, 50, 80, 70, 30, 28, 35, 22, 25] # Plot horizontal bar plot plt.barh(categories, values, color='purple') plt.xlabel('Sales (in thousands)') plt.ylabel('Car Models') plt.title('Car Model Sales Performance') plt.show()