0% found this document useful (0 votes)
11 views12 pages

Dev Exp2 Word-1

Uploaded by

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

Dev Exp2 Word-1

Uploaded by

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

WORKING WITH NUMPY, ARRAYS, PANDAS, DATA FRAMES AND BASIC

PLOTS USING MATPLOTLIB

BAR GRAPH

PROGRAM :

from google.colab import drive


drive.mount('/content/drive')
import pandas as pd
import matplotlib.pyplot as plt
data_path = '/content/drive/MyDrive/diabetes_prediction_dataset.csv'
data = pd.read_csv(data_path)
age = data['age']
blood_glucose_level = data['blood_glucose_level']
plt.figure(figsize=(10, 6))
plt.bar(age, blood_glucose_level, color='skyblue'
plt.xlabel('age')
plt.ylabel('blood_glucose_level')
plt.title('Bar Graph For Prediction Of Diabetes')
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
plt.show()

OUTPUT :
LINE CHART
PROGRAM :

from google.colab import drive


drive.mount('/content/drive')
import pandas as pd
import matplotlib.pyplot as plt
data_path = '/content/drive/MyDrive/diabetes_prediction_dataset.csv'
data = pd.read_csv(data_path)
data = data.head(50)
age = data['age']
hypertension = data['hypertension']
plt.figure(figsize=(10, 6))
plt.plot(age, hypertension, marker='o', linestyle='-')
plt.xlabel('age')
plt.ylabel('hypertension')
plt.title('Line Chart of the First 50 Data Points')
plt.xticks(rotation=45, ha='right')
plt.tight_layout()
plt.show()

OUTPUT :
PIE CHART

PROGRAM :

from google.colab import drive


drive.mount(‘/content/drive’)
import pandas as pd
import matplotlib.pyplot as plt
data_path = ‘/content/drive/MyDrive/diabetes_prediction_dataset.csv’
data = pd.read_csv(data_path)
data = data.head(50)
age = data[‘age’]
bmi = data[‘bmi’]
plt.figure(figsize=(8, 8))
plt.pie(bmi, labels=age, autopct=’%1.1f%%’, startangle=150)
plt.title(‘Pie Chart of the First 50 Data Points’)
plt.tight_layout()
plt.show()

OUTPUT :
TABLE CHART

PROGRAM :

from google.colab import drive


drive.mount('/content/drive')
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
mf=pd.read_csv('/content/drive/MyDrive/diabetes_prediction_dataset.csv')
mf.head(5)

OUTPUT :
SCATTER PLOT

PROGRAM :

from google.colab import drive


drive.mount('/content/drive')
import pandas as pd
import matplotlib.pyplot as plt
data_path = '/content/drive/MyDrive/diabetes_prediction_dataset.csv'
data = pd.read_csv(data_path)
data = data.head(50)
age = data['age']
diabetes = data['diabetes']
plt.figure(figsize=(10, 6))
plt.scatter(age, diabetes, s=10, c='blue', marker='o')
plt.xlabel('age')
plt.ylabel('diabetes')
plt.title('Scatter Plot of the First 50 Data Points')
plt.tight_layout()
plt.show()

OUTPUT ;
HISTOGRAM
PROGRAM :

from google.colab import drive


drive.mount('/content/drive')
import pandas as pd
import matplotlib.pyplot as plt
data_path = '/content/drive/MyDrive/diabetes_prediction_dataset.csv'
data = pd.read_csv(data_path)
data = data.head(50)
diabetes = data['diabetes']
plt.figure(figsize=(10, 6))
plt.hist(diabetes, bins=20, color='skyblue', edgecolor='black')
plt.xlabel('age')
plt.ylabel('diabetes')
plt.title('Histogram of the First 50 Data Points')
plt.tight_layout()
plt.show()

OUTPUT :
POLAR CHART
PROGRAM :

from google.colab import drive


drive.mount('/content/drive')
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
data_path = '/content/drive/MyDrive/diabetes_prediction_dataset.csv'
data = pd.read_csv(data_path)
data = data.head(50)
age = data['age']
blood_glucose_level = data['blood_glucose_level']
plt.figure(figsize=(7, 7))
num_age = len(age)
angles = np.linspace(0, 2 * np.pi, num_age, endpoint=False).tolist()
values = np.concatenate((blood_glucose_level, [blood_glucose_level[0]]))
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.fill(angles, blood_glucose_level, 'skyblue', alpha=0.6)
ax.set_xticks(angles)
ax.set_xticklabels(age)
ax.set_yticklabels([])
plt.title('Polar Chart of the First 50 Data Points')
plt.tight_layout()
plt.show()

OUTPUT :
AREA PLOT

PROGRAM :

import pandas as pd
import matplotlib.pyplot as plt
file_path = '/content/drive/MyDrive/diabetes_prediction_dataset.csv'
df = pd.read_csv(file_path)
X = df['age']
Y = df['diabetes']
plt.figure(figsize=(10, 6))
plt.fill_between(X, Y, color='blue', alpha=0.2)
plt.title('Area Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True)
plt.show()

OUTPUT :
STACKED PLOT
PROGRAM :

import pandas as pd
import matplotlib.pyplot as plt
file_path = '/content/drive/MyDrive/diabetes_prediction_dataset.csv'
df = pd.read_csv(file_path)
X = df['age']
Y1 = df['blood_glucose_level']
Y2 = df['diabetes']
y3=df['heart_disease']
y4=df['hypertension']
plt.figure(figsize=(10, 6))
plt.stackplot(X, Y1, Y2,y3,y4, labels=['age','blood_glucose_level',
'diabetes','heart_disease','hypertension'],
alpha=0.5)
plt.title('Stacked Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.legend(loc='upper left')
plt.grid(True)
plt.show()

OUTPUT :
DASHBOARD
JUSTIFICATION

Not all datasets are equally suitable for visualizing using different types of charts. The choice
of the appropriate chart or visualization method depends on the characteristics of the data, the
goals of the analysis, and the story you want to convey.

Here's a justification for why different datasets may or may not be suitable for visualization
with different types of charts:

1. Data Type:
 Continuous Numerical Data: Line charts, scatter plots, and histograms work
well for visualizing trends and distributions in continuous numerical data.
 Categorical Data: Bar charts, pie charts, and stacked bar charts are suitable
for showing the distribution of categories within a dataset.
2. Data Distribution:
 Normal Distribution: Histograms, box plots, and normal probability plots are
useful for examining data that follows a normal distribution.
 Skewed Data: For data with a skewed distribution, transformations or
different types of charts might be more appropriate to make the data more
interpretable.
3. Data Size:
 Large Datasets: Large datasets may be challenging to visualize
comprehensively. In such cases, summary statistics, aggregations, and
subsampling are often employed.
 Small Datasets: Smaller datasets can be visualized in greater detail, and
various chart types can be applied more effectively.
4. Data Relationships:
 Correlations: Scatter plots can help visualize relationships and correlations
between two numerical variables.
 Multiple Variables: For datasets with multiple variables, parallel coordinate
plots or heatmaps can be helpful to visualize relationships among variables.
5. Temporal Data:
 Time Series Data: Line charts are typically used to visualize time series data,
which shows how data changes over time.
 Seasonal Data: For data with seasonal patterns, seasonal decomposition or
multiple line charts can be useful.
6. Data Storytelling:
 Comparison: Bar charts, box plots, and radar charts are useful for comparing
categories or values.
 Distribution: Histograms and density plots are effective for showing the
distribution of data.
 Change Over Time: Line charts, area charts, and stacked area charts are
valuable for illustrating trends over time.
7. Data Complexity:
Complex Data: Complex datasets might require more advanced visualization
techniques, such as network graphs, Sankey diagrams, or heatmaps.
 Simple Data: Simple datasets can often be visualized with basic charts like
bar charts or scatter plots.
8. Data Exploration vs. Presentation:
 Exploratory Data Visualization: When exploring data, you may use a variety
of charts to gain insights without being bound by presentation constraints.
 Presentation: In a presentation or report, you may use specific chart types that
best communicate your findings to the audience.

In summary, the choice of visualization depends on the nature of the data and the goals of our
analysis. While some datasets are amenable to multiple chart types, others may have
characteristics that make certain charts more appropriate for effective communication and
interpretation. It's important to choose the visualization method that best serves the purpose
of your analysis and helps tell the story you want to convey.

You might also like