Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

Python Exp 11

Ss

Uploaded by

hareesahamed35
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Python Exp 11

Ss

Uploaded by

hareesahamed35
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Date:

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()

df['Total_Sales'] = df[['Sales_Q1', 'Sales_Q2', 'Sales_Q3', 'Sales_Q4']].sum(axis=1)


plt.figure(figsize=(10, 6))
plt.bar(df['Product'], df['Total_Sales'], color='skyblue')
plt.title('Total Sales by Product')
plt.xlabel('Product')
plt.ylabel('Total Sales')
plt.grid(axis='y')
plt.savefig('bar_plot_total_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:

1. Line Plot (line_plot_sales.png):

2. Bar Plot (bar_plot_total_sales.png):


3. Scatter Plot (scatter_plot_q1_vs_q4.png):

You might also like