Python Exp 11
Python Exp 11
Exp. No:11
Visualizing the data using Matplot Lib
Code:
import pandas as pd
import matplotlib.pyplot as plt
data = {
'Product': ['A', 'B', 'C', 'D'],
'Sales_Q1': [1500, 2300, 1200, 1800],
'Sales_Q2': [1600, 2400, 1300, 1900],
'Sales_Q3': [1700, 2500, 1400, 2000],
'Sales_Q4': [1800, 2600, 1500, 2100]
}
df = pd.DataFrame(data)
plt.figure(figsize=(10, 6))
for product in df['Product']:
plt.plot(['Q1', 'Q2', 'Q3', 'Q4'], df[df['Product'] == product].iloc[0, 1:],
marker='o', label=product)
plt.title('Sales over Quarters by Product')
plt.xlabel('Quarter')
plt.ylabel('Sales')
plt.legend(title='Product')
plt.grid(True)
plt.savefig('line_plot_sales.png')
plt.show()
plt.figure(figsize=(10, 6))
plt.scatter(df['Sales_Q1'], df['Sales_Q4'], color='red')
plt.title('Sales in Q1 vs Sales in Q4')
plt.xlabel('Sales Q1')
plt.ylabel('Sales Q4')
plt.grid(True)
plt.savefig('scatter_plot_q1_vs_q4.png')
plt.show()
Result:
• Line Plot: Provides insights into how sales for each product vary across different
quarters.
• Bar Plot: Easily compares the total sales figures of different products.
• Scatter Plot: Helps in understanding the correlation between sales in Q1 and Q4.
Output: