import matplotlib.pyplot as plt
import numpy as np
# 示例数据
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [100, 120, 90, 130, 150, 170]
# 绘制折线图
plt.plot(months, sales, marker='o')
plt.title('Monthly Sales Trend')
plt.xlabel('Month')
plt.ylabel('Sales (in thousands)')
plt.grid(True)
plt.show()
]]>
products = ['Product A', 'Product B']
jan_sales = [50, 50]
feb_sales = [60, 60]
mar_sales = [40, 50]
bar_width = 0.35
index = np.arange(len(products))
plt.bar(index, jan_sales, bar_width, label='Jan')
plt.bar(index + bar_width, feb_sales, bar_width, label='Feb')
plt.bar(index + 2*bar_width, mar_sales, bar_width, label='Mar')
plt.xlabel('Products')
plt.ylabel('Sales')
plt.title('Comparison of Product Sales')
plt.xticks(index + bar_width, products)
plt.legend()
plt.show()
]]>