0% found this document useful (0 votes)
27 views13 pages

Practical D.V

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views13 pages

Practical D.V

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Dr.

Rafiq Zakaria Campus


Maulana Azad College of Arts, Commerce & Science, Aurangabad.
P.G. Department of Computer Science

Certificat
This is to certify that Mr. /Ms. Dheya Alhaq Abdo Ahmed Alnuzaili

Seat No.03 of M.Sc. Computer Science, has satisfactorily completed the practical

work of Semester 1 for Course Code Data Visualization Course Name Computer

Science during the academic year 2023- 2024.

Subject Incharge Head

Dr. Ruheena Quadri Dr. Shaikh Akhil

Examiner
Dr. Rafiq Zakaria Campus
PG Department of Computer Science
Maulana Azad College of Arts,Commerce and Science

Paper: CCS/MJT/501 – Practical Based on CCS/MJP/ Data Visualization


Practical - 3

Aim: - Case study on Visualizing Global Health data: Analysing and presenting health indicators across
countries to identify patterns and disparities

1- Boxplot

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Assuming you have a dataset named 'health_data'


data = {
'Country': ['India', 'Yemen', 'Russia', 'USA', 'KSA'],
'Life_Expectancy': [95, 73, 82, 80, 76],
'Infant_Mortality_Rate': [10, 15, 5, 12, 8],
'Healthcare_Expenditure': [5000, 2000, 7000, 6500, 9500],
'Cause_of_Mortality': ['Infectious Diseases', 'Heart Disease',
'Cancer', 'Infectious Diseases', 'Respiratory Diseases']
}

health_data = pd.DataFrame(data)

# 1. Boxplot (Life Expectancy)


sns.boxplot(x='Country', y='Life_Expectancy', data=health_data)
plt.title('Boxplot of Life Expectancy Across Countries')
plt.xticks(rotation=45, ha='right')
plt.show()

OutPut:
2- Histogram

# 2. Histogram (Infant Mortality Rate)


plt.hist(health_data['Infant_Mortality_Rate'], bins=20,
edgecolor='black')
plt.title('Histogram of Infant Mortality Rate Across Countries')
plt.xlabel('Infant Mortality Rate')
plt.ylabel('Number of Countries')
plt.show()

Output:
3- Heatmap
# 3. Heatmap (Correlation Matrix of Numeric Health Indicators)
numeric_columns = health_data.select_dtypes(include=['int64',
'float64']).columns
correlation_matrix = health_data[numeric_columns].corr()
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt='.2f')
plt.title('Correlation Matrix of Numeric Health Indicators')
plt.show()

Output:
4- Bar Chart
# 4. Bar Chart (Healthcare Expenditure)
plt.bar(health_data['Country'], health_data['Healthcare_Expenditure'])
plt.title('Healthcare Expenditure Across Countries')
plt.xlabel('Country')
plt.ylabel('Healthcare Expenditure')
plt.xticks(rotation=45, ha='right')
plt.show()

Output:
5- Pie Chart

# 5. Pie Chart (Distribution of Causes of Mortality)


cause_of_mortality_counts =
health_data['Cause_of_Mortality'].value_counts()
plt.pie(cause_of_mortality_counts,
labels=cause_of_mortality_counts.index, autopct='%1.1f%%',
startangle=90)
plt.title('Distribution of Causes of Mortality Across Countries')
plt.show()

Output:
Dr. Rafiq Zakaria Campus
PG Department of Computer Science
Maulana Azad College of Arts,Commerce and Science

Paper: CCS/MJT/501 – Practical Based on CCS/MJP/ Data Visualization


Practical - 4

Aim: - Interactive sales dashboard : Designing an interactive dashboard to explore sales data and influence patterns
with example
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import pandas as pd
import plotly.express as px

# Sample Sales Data


sales_data = pd.DataFrame({
'Date': pd.date_range(start='2023-01-01', periods=8, freq='D'),
'Product': ['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B'],
'Sales': [100, 120, 130, 80, 110, 90, 140, 75],
'Region': ['North', 'South', 'East', 'West', 'North', 'South', 'East', 'West']
})

# Initialize the Dash app


app = dash.Dash(__name__)

# Layout of the Dashboard


app.layout = html.Div(
className='container',
children=[
html.H1("Interactive Sales Dashboard"),
dcc.Dropdown(
id='product-dropdown',
options=[{'label': prod, 'value': prod} for prod in
sales_data['Product'].unique()],
value='A',
multi=False,
style={'width': '50%'}
),

dcc.Graph(id='sales-line-chart'),

dcc.RangeSlider(
id='date-slider',
min=sales_data['Date'].min().timestamp(),
max=sales_data['Date'].max().timestamp(),
marks={int(ts): pd.to_datetime(ts, unit='s').strftime('%Y-%m-%d') for ts
in
range(int(sales_data['Date'].min().timestamp()),
int(sales_data['Date'].max().timestamp()), 86400 * 30)},
step=None,
value=[sales_data['Date'].min().timestamp(),
sales_data['Date'].max().timestamp()]
)
]
)
Following The code:{ http://127.0.0.1:8050/}

# Callback to update the sales line chart based on user input


@app.callback(
Output('sales-line-chart', 'figure'),
[Input('product-dropdown', 'value'),
Input('date-slider', 'value')]
)
def update_chart(selected_product, selected_date_range):
filtered_data = sales_data[
(sales_data['Product'] == selected_product) &
(sales_data['Date'] >= pd.to_datetime(selected_date_range[0],
unit='s')) &
(sales_data['Date'] <= pd.to_datetime(selected_date_range[1],
unit='s'))
]

fig = px.line(filtered_data, x='Date', y='Sales', color='Region',


title=f'Sales for Product {selected_product}')
return fig

# Run the app


if __name__ == '__main__':
app.run_server(debug=True)

Output:
Dr. Rafiq Zakaria Campus
PG Department of Computer Science
Maulana Azad College of Arts,Commerce and Science

Paper: CCS/MJT/501 – Practical Based on CCS/MJP/ Data Visualization


Practical - 5

Aim: Network analysis: visualizing social networks or organizational structure to reveal connections and
influence pattern.
import networkx as nx
import matplotlib.pyplot as plt

# Create a simple organizational structure network


G = nx.Graph()

# Add employees as nodes


employees = ['Alice', 'Bob', 'Charlie', 'David', 'Eve']
G.add_nodes_from(employees)

# Define professional relationships (edges)


relationships = [('Alice', 'Bob'), ('Alice', 'Charlie'), ('Bob', 'David'),
('Charlie', 'Eve')]

G.add_edges_from(relationships)

# Visualize the organizational structure


pos = nx.spring_layout(G) # Force-directed layout
nx.draw(G, pos, with_labels=True, font_weight='bold',
node_color='lightblue', font_color='black', node_size=800,
edge_color='gray', width=2)

plt.title('Organizational Structure')
plt.show()

Output:
Dr. Rafiq Zakaria Campus
PG Department of Computer Science
Maulana Azad College of Arts,Commerce and Science

Paper: CCS/MJT/501 – Practical Based on CCS/MJP/ Data Visualization


Practical - 6

Aim: Geospatial data visualization :mapping and analyzing geographic data such as population density
distribution of resources or climate pattern

import geopandas as gpd


import matplotlib.pyplot as plt

# Load world shapefile data


world =
gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

# Load population data


pop_data = gpd.read_file(r"E:\MSC\practical\D.V\natural
earth\ne_110m_admin_0_countries.shp")

# Merge world data with population data


world = world.merge(pop_data, how='left', left_on='iso_a3',
right_on='ISO_A3')

# Plotting
fig, ax = plt.subplots(1, 1, figsize=(15, 10))
world.boundary.plot(ax=ax, linewidth=0.8)
world.plot(column='pop_est', ax=ax, legend=True,
legend_kwds={'label': "Population by Country"})
plt.title('World Population Density')
plt.show()

Output:
Dr. Rafiq Zakaria Campus
PG Department of Computer Science
Maulana Azad College of Arts,Commerce and Science

Paper: CCS/MJT/501 – Practical Based on CCS/MJP/ Data Visualization


Practical - 7

Aim: Time series Visualization: Analyzing temporal data, such as stock prices or weather patterns to
identify trends and make predictions

import yfinance as yf
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
# Fetch historical stock data
symbol = "AAPL"
start_date = "2022-01-01"
end_date = "2023-01-01"
stock_data = yf.download(symbol, start=start_date, end=end_date)

# Plotting interactive time series chart


fig = go.Figure()
# Add stock closing prices as a line chart
fig.add_trace(go.Scatter(x=stock_data.index, y=stock_data['Close'],
mode='lines', name='Closing Price'))
# Add 30-day moving average
fig.add_trace(go.Scatter(x=stock_data.index,
y=stock_data['Close'].rolling(window=30).mean(),
mode='lines', name='30-day Moving Average',
line=dict(dash='dash')))
# Add trendlines
fig.update_layout(annotations=[
dict(
x="2022-08-01",
y=stock_data['Close'].max(),
xref="x",
yref="y",
text="Upward Trend",
showarrow=True,
arrowhead=4,
ax=0,
ay=-40
)
])
# Add titles and labels
fig.update_layout(
title=f'{symbol} Stock Price Analysis',
xaxis_title='Date',
yaxis_title='Stock Price (USD)',
template='plotly_dark'
)
Output:

You might also like