Date:
Exp. No:11
Visualizing the data using Matplot Lib
Code:
import pandas as pd
import [Link] 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 = [Link](data)
[Link](figsize=(10, 6))
for product in df['Product']:
[Link](['Q1', 'Q2', 'Q3', 'Q4'], df[df['Product'] == product].iloc[0, 1:],
marker='o', label=product)
[Link]('Sales over Quarters by Product')
[Link]('Quarter')
[Link]('Sales')
[Link](title='Product')
[Link](True)
[Link]('line_plot_sales.png')
[Link]()
df['Total_Sales'] = df[['Sales_Q1', 'Sales_Q2', 'Sales_Q3', 'Sales_Q4']].sum(axis=1)
[Link](figsize=(10, 6))
[Link](df['Product'], df['Total_Sales'], color='skyblue')
[Link]('Total Sales by Product')
[Link]('Product')
[Link]('Total Sales')
[Link](axis='y')
[Link]('bar_plot_total_sales.png')
[Link]()
[Link](figsize=(10, 6))
[Link](df['Sales_Q1'], df['Sales_Q4'], color='red')
[Link]('Sales in Q1 vs Sales in Q4')
[Link]('Sales Q1')
[Link]('Sales Q4')
[Link](True)
[Link]('scatter_plot_q1_vs_q4.png')
[Link]()
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:
1. Line Plot (line_plot_sales.png):
2. Bar Plot (bar_plot_total_sales.png):
3. Scatter Plot (scatter_plot_q1_vs_q4.png):