VISVESVARAYA TECHNOLOGICAL UNIVERSITY
Jnana Sangama, Belagavi - 590 018,
Karnataka
Acharya Institute of Technology
Acharya Dr Sarvepalli. Radhakrishnan Road
Acharya P.O Soladevanahalli, Bengaluru-560107
LABORATORY MANUAL
DATA VISUALIZATION WITH PYTHON
BCS358D
III Semester
Prepared by:
1. Gowtham Raj M
2. Sneha N P
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
(Accredited by NBA)
Table of contents
Vision, Mission, Motto of Institute I
Vision, Mission of Department II
Program Educational Objectives (PEOs) III
Program Specific Outcomes (PSOs) IV
Program outcomes (POs) V
Course outcomes of course (COs) VI
CO-PO matrix VII
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
VISION OF THE INSTITUTE
Acharya Institute of Technology, committed to the cause of value -based education in all disciplines,
envisions itself as fountainhead of innovative human enterprise, with inspirational initiatives for
Academic Excellence
MISSION OF THE INSTITUTE
Acharya Institute of Technology, strives to provide excellent academic ambiance to the students for
achieving global standards of technical education, foster intellectual and personal development,
meaningful research and ethical service to sustainable societal needs.
VISION OF THE DEPARTMENT
Envisions to be recognized for quality education and research in the field of Computing, leading to
creation of globally competent engineers, who are innovative and adaptable to the changing demands of
industry and society.
MISSION OF THE DEPARTMENT
1. Act as a nurturing ground for young computing aspirants to attain excellence by imparting quality
education.
2. Collaborate with industries and provide exposure to latest tools/ technologies.
3. Create an environment conducive for research and continuous learning
PROGRAM EDUCATIONAL OBJECTIVES (PEOs)
1. Students shall have a successful carrier in academia, R&D organizations, IT industry or pursue higher
studies in specialized field of Computer Science & Engineering and allied disciplines.
2. Students shall be competent, creative and a valued professional in the chosen field
3. Students shall engage in life-long learning, professional development and adapt to the working
environment quickly
4. Students shall become effective collaborators and exhibit high level of professionalism by leading or
participating in addressing technical, business, environmental and societal challenges.
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
PROGRAM OUTCOMES (POs)
Engineering Graduates will be able to:
1. Engineering knowledge:
Apply the knowledge of mathematics, science, engineering fundamentals, and an engineering
specialization to the solution of complex engineering problems.
2. Problem analysis:
Identify, formulate, review research literature, and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for
the public health and safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions
in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of engineering practice.
9. Individual and teamwork: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
and management principles and apply these to one’s own work, as a member and leader in a team,
to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life -long learning in the broadest context of technological change.
PROGRAM SPECIFIC OUTCOMES (PSOs)
PSO-1 Students shall apply the knowledge of hardware, system software, algorithms, computer networks
and databases for real world problems.
PSO-2 Students shall design, analyses and develop efficient and secure algorithms using appropriate data
structures, databases for processing of data.
PSO-3 Students shall be capable of developing stand alone, embedded and web-based solutions having
easy to operate interface using software engineering practices and contemporary computer programming
languages.
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
SL.NO Name of Program Page No
1 a) Write a python program to find the best of two test average marks out of three
test’s marks accepted
from the user. 5-6
b) Develop a Python program to check whether a given number is palindrome or not
andalso count the
number of occurrences of each digit in the input number.
2 a) Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program which
accepts a value for N
(where N >0) as input and pass this value to the function. Display suitable error
message if the condition 7-8
for input value is not followed.
b) Develop a python program to convert binary to decimal, octal to hexadecimal
using functions.
3 a) Write a Python program that accepts a sentence and find the number of words,
digits, uppercase letters and
lowercase letters. 9-10
b) Write a Python program to find the string similarity between two given strings
4 a) Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib.
b) Write a Python program to Demonstrate how to Draw a Scatter Plot using 11-12
Matplotlib.
5 a) Write a Python program to Demonstrate how to Draw a Histogram Plot using
Matplotlib. 13-14
b) Write a Python program to Demonstrate how to Draw a Pie Chart using Matplotlib.
6 a) Write a Python program to illustrate Linear Plotting using Matplotlib.
b) Write a Python program to illustrate liner plotting with line formatting using 15-16
Matplotlib.
7 Write a Python program which explains uses of customizing seaborn plots with
Aesthetic functions. 17
8 Write a Python program for plotting different types of plots using Bokeh.
18
9 Write a Python program to draw 3D Plots using Plotly Libraries.
20
10 a) Write a Python program to draw Time Series using Plotly Libraries.
b) Write a Python program for creating Maps using Plotly Libraries. 21-22
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
Evaluation Rubrics for lab Programs (Max marks 50)
A. Lab write-up and execution rubrics(Max marks 30)
Good Average
a. Write Up Demonstrate good knowledge Moderate understanding of
(5 marks) of language constructs and language constructs (3)
programming practice (5)
b. Execution Program handles all possible Partial executions /poor error
(15marks) conditions and results with handling (8)
satisfying results. (15)
c. Marks for Lab Meticulous documentation of Moderate formatting of output
Record changes made and results and average documentation (5)
(10 Marks) obtained are in proper format
(10)
B. Test: (Max marks 20)
Good Average
a. Write Up Demonstrate good knowledge Moderate
(6 marks) of language constructs and understanding of
programming practice (6) language constructs
(3)
b. Execution Program handles all possible Partial executions
(10 marks) conditions and results with /poor errorhandling
satisfying results. (10) (5)
c. Viva Explain the complete Adequately provides
(4 Marks) program, with related explanation (2)
concepts (4)
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
1a. Write a python program to find the best of two test average marks out of three test's marks
accepted from the user.
mark1=float(input("Entar First Test Mark:"))
mark2=float(input("Entar Second Test Mark:"))
mark3=float(input("Entar Third Test Mark:"))
if(mark1 >= mark2) and (mark1>= mark2):
if(mark2>=mark3):
print ("The best two test marks are",mark1,mark2)
print ("The average of best of two test marks out of three marks is", (mark1+mark2)/2)
else:
print ("The best two test marks are",mark1,mark3)
print ("The average of best of two test marks out of three marks is",(mark1+mark3)/2)
elif(mark2 >= mark1) and (mark2>= mark3):
if(mark1>=mark3):
print ("The best two test marks are",mark2,mark1)
print ("The average of best of two test marks out of three marks is", (mark2+mark1)/2)
else:
print ("The best two test marks are",mark2,mark3)
print ("The average of best of two test marks out of three marks is", (mark2+mark3)/2)
else:
if(mark1>=mark2):
print ("The best two test marks are",mark1,mark3)
print ("The average of best of two test marks out of three marks is", (mark1+mark3)/2)
else:
print ("The best two test marks are",mark2,mark3)
print ("The average of best of two test marks out of three marks is", (mark2+mark3)/2)
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
1b. Develop a Python program to check whether a given number is palindrome or not and also
count the number of occurrences of each digit in the input number
n=int(input("Enter n value"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
number_str = str(temp)
occurrences = {}
for digit in number_str:
if digit in occurrences:
occurrences[digit]+= 1
else:
occurrences[digit]= 1
print("Digit occurrences:",occurrences)
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
2a. Defined as a function F as Fn = Fn-1 + Fn-2. Write a Python program which accepts a value for
N (where N >0) as input and pass this value to the function. Display suitable error message if the
condition for input value is not followed.
def fibonacci(n):
# Check if input value is valid
if n <= 0:
raise ValueError("Invalid input. N must be greater than 0.")
# Base cases for Fibonacci sequence
if n == 1:
return 0
elif n == 2:
return 1
# Calculate the Fibonacci number
fib_n_minus_2 = 0
fib_n_minus_1 = 1
fib_n = 0
for i in range(3, n+1):
fib_n = fib_n_minus_1 + fib_n_minus_2
fib_n_minus_2 = fib_n_minus_1
fib_n_minus_1 = fib_n
return fib_n
try:
N = int(input("Enter a value for N (N > 0): "))
result = fibonacci(N)
print("Fibonacci number at position", N, "is", result)
except ValueError as e:
print(str(e))
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
2b. Develop a python program to convert binary to decimal, octal to hexadecimal using functions
def binary_to_decimal(binary):
decimal = 0
power = 0
while binary > 0:
last_digit = binary % 10
decimal += last_digit * (2 ** power)
binary //= 10
power += 1
return decimal
def octal_to_hexadecimal(octal):
decimal = 0
power = 0
while octal > 0:
last_digit = octal % 10
decimal += last_digit * (8 ** power)
octal //= 10
power += 1
hexadecimal = ""
hex_digits = "0123456789ABCDEF"
while decimal > 0:
remainder = decimal % 16
hexadecimal = hex_digits[remainder] + hexadecimal
decimal //= 16
return hexadecimal
# Test the functions
binary_input = input("Enter a binary number: ")
decimal_result = binary_to_decimal(int(binary_input))
print(f"Decimal equivalent: {decimal_result}")
octal_input = input("Enter an octal number: ")
hexadecimal_result = octal_to_hexadecimal(int(octal_input))
print(f"Hexadecimal equivalent: {hexadecimal_result}")
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
3a. Write a Python program that accepts a sentence and find the number of words, digits,
uppercase letters and lowercase letters.
def analyze_sentence(sentence):
word_count = len(sentence.split())
digit_count = sum(char.isdigit() for char in sentence)
uppercase_count = sum(char.isupper() for char in sentence)
lowercase_count = sum(char.islower() for char in sentence)
return word_count, digit_count, uppercase_count, lowercase_count
user_input = input("Enter a sentence: ")
word_count, digit_count, uppercase_count, lowercase_count = analyze_sentence(user_input)
print("Number of words:", word_count)
print("Number of digits:", digit_count)
print("Number of uppercase letters:", uppercase_count)
print("Number of lowercase letters:", lowercase_count)
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
3b. Write a Python program to find the string similarity between two given strings
Sample Output: Sample Output:
Original string: Original string:
Python Exercises Python Exercises
Python Exercises Python Exercise
Similarity between two said strings: Similarity between two said strings: 1.0
0.967741935483871
def string_similarity(string1, string2):
similarity_ratio = SequenceMatcher(None, string1, string2).ratio()
return similarity_ratio
# Sample Input
string1=input("Enter string 1")
string2=input("Enter string 2")
# Find string similarity
#similarity = string_similarity(string1, string2)
print("Original string 1:", string1)
print("Original string 2:", string2)
print("Similarity between two strings:")
print(string_similarity(string1, string2))
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
4a Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib.
import matplotlib.pyplot as plt
# Sample data
categories = ['Category A', 'Category B', 'Category C', 'Category D']
values = [25, 40, 30, 35]
# Create a bar plot
plt.bar(categories, values, color='skyblue')
# Adding labels and a title
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Plot Example')
# Display the plot
plt.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
4b) Write a Python program to Demonstrate how to Draw a Scatter Plot using Matplotlib
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 12, 5, 20, 15]
# Create a scatter plot
plt.scatter(x, y, c='blue', label='Data Points', marker='o')
# Adding labels and a title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot Example')
# Add a legend
plt.legend()
# Display the plot
plt.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
5a) Write a Python program to Demonstrate how to Draw a Histogram Plot using Matplotlib.
import matplotlib.pyplot as plt
import numpy as np
# Generate random data for the histogram
data = np.random.randn(1000) # 1000 random data points
# Create a histogram
plt.hist(data, bins=20, color='skyblue', edgecolor='black')
# Adding labels and a title
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.title('Histogram Plot Example')
# Display the plot
plt.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
5b) Write a Python program to Demonstrate how to Draw a Pie Chart using Matplotlib.
import matplotlib.pyplot as plt
# Sample data
labels = ['Category A', 'Category B', 'Category C', 'Category D']
sizes = [30, 15, 45, 10]
colors = ['lightcoral', 'lightskyblue', 'lightgreen', 'lightpink']
# Create a pie chart
plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', startangle=140)
# Adding a title
plt.title('Pie Chart Example')
# Display the plot
plt.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
plt.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
6a) Write a Python program to illustrate Linear Plotting using Matplotlib.
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 3, 8, 10]
# Create a linear plot
plt.plot(x, y, marker='o', linestyle='-', color='blue', label='Linear Data')
# Adding labels and a title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Linear Plot Example')
# Add a legend
plt.legend()
# Display the plot
plt.grid(True)
plt.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
6b. Write a Python program to illustrate liner plotting with line formatting using Matplotlib.
import matplotlib.pyplot as plt
# Sample data
x = [1, 2, 3, 4, 5]
y1 = [2, 4, 6, 8, 10]
y2 = [1, 3, 5, 7, 9]
# Create a linear plot with line formatting
plt.plot(x, y1, color='blue', linestyle='-', marker='o', label='Line 1')
plt.plot(x, y2, color='red', linestyle='--', marker='x', label='Line 2')
# Adding labels and a title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Linear Plot with Line Formatting Example')
# Add a legend
plt.legend()
# Display the plot
plt.grid(True)
plt.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
7 Write a Python program which explains uses of customizing seaborn plots with Aesthetic
functions.
import seaborn as sns
import matplotlib.pyplot as plt
# Sample data
tips = sns.load_dataset("tips")
# Set the style of the plot
sns.set_style("whitegrid")
# Create a scatter plot with custom colors and styles
sns.scatterplot(x="total_bill", y="tip", data=tips, hue="time", style="time", palette="Set1")
# Customize the labels and title
plt.xlabel("Total Bill ($)")
plt.ylabel("Tip ($)")
plt.title("Scatter Plot of Total Bill vs. Tip")
# Add a legend
plt.legend(title="Time of Day")
# Show the plot
plt.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
8) Write a Python program for plotting different types of plots using Bokeh.
from bokeh.plotting import figure, show, output_file
from bokeh.io import export_png
from bokeh.models import ColumnDataSource
from bokeh.transform import dodge
import pandas as pd
# Sample data
data = {
'Categories': ['Category A', 'Category B', 'Category C', 'Category D'],
'Values': [25, 40, 30, 35]
}
# Create a bar chart
bar_data = pd.DataFrame(data)
bar_source = ColumnDataSource(bar_data)
bar_plot = figure(x_range=bar_data['Categories'], plot_height=350, title='Bar Chart Example',
toolbar_location=None, tools="")
bar_plot.vbar(x='Categories', top='Values', source=bar_source, width=0.5, color="blue")
# Create a scatter plot
scatter_x = [1, 2, 3, 4, 5]
scatter_y = [10, 12, 5, 20, 15]
scatter_plot = figure(title='Scatter Plot Example', x_axis_label='X-axis', y_axis_label='Y-axis')
scatter_plot.circle(scatter_x, scatter_y, size=10, color='red', legend_label='Data Points')
# Create a line chart
line_x = [1, 2, 3, 4, 5]
line_y = [2, 4, 6, 8, 10]
line_plot = figure(title='Line Chart Example', x_axis_label='X-axis', y_axis_label='Y-axis')
line_plot.line(line_x, line_y, line_width=2, line_color='green', legend_label='Line')
# Create a pie chart
pie_data = pd.DataFrame({'categories': ['A', 'B', 'C', 'D'], 'values': [30, 15, 45, 10]})
pie_chart = figure(plot_height=350, title='Pie Chart Example', toolbar_location=None,
tools="hover", tooltips="@categories: @values%", x_range=(-0.5, 1.0))
pie_chart.wedge(x=0, y=1, radius=0.4, start_angle=dodge('categories', -0.5, range=pie_chart.x_range),
end_angle=dodge('categories', 0.5, range=pie_chart.x_range), source=pie_data,
line_color="white", fill_color="color", legend_field="categories")
# Save the plots to HTML files
output_file('bar_chart.html')
show(bar_plot)
output_file('scatter_plot.html')
show(scatter_plot)
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
output_file('line_chart.html')
show(line_plot)
output_file('pie_chart.html')
show(pie_chart)
# Export a PNG image of the pie chart
export_png(pie_chart, filename="pie_chart.png")
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
9) Write a Python program to draw 3D Plots using Plotly Libraries.
import plotly.express as px
import plotly.graph_objects as go
# Create a 3D scatter plot
scatter_3d = px.scatter_3d(x=[1, 2, 3, 4, 5],
y=[10, 12, 5, 20, 15],
z=[5, 7, 9, 10, 12],
title='3D Scatter Plot Example',
labels={'x': 'X-axis', 'y': 'Y-axis', 'z': 'Z-axis'})
# Show the 3D scatter plot
scatter_3d.show()
# Create a 3D surface plot
surface_data = [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15]
]
surface_plot = go.Figure(data=[go.Surface(z=surface_data)])
surface_plot.update_layout(scene=dict(zaxis_title='Z-axis', xaxis_title='X-axis', yaxis_title='Y-axis'),
title='3D Surface Plot Example')
# Show the 3D surface plot
surface_plot.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
10 a) Write a Python program to draw Time Series using Plotly Libraries.
import plotly.express as px
import pandas as pd
# Sample time series data
data = {
'Date': pd.date_range(start='2023-01-01', periods=10, freq='D'),
'Value': [10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
}
# Create a time series line plot
time_series_plot = px.line(data, x='Date', y='Value', title='Time Series Plot Example',
labels={'Value': 'Values'}, markers=True)
# Show the time series plot
time_series_plot.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D
10 b) Write a Python program for creating Maps using Plotly Libraries.
import plotly.express as px
# Sample data
data = px.data.gapminder()
# Create a choropleth world map
world_map = px.choropleth(data, locations="iso_alpha", color="lifeExp",
hover_name="country", animation_frame="year",
title="World Map with Life Expectancy Over Time",
color_continuous_scale=px.colors.sequential.Plasma)
# Show the map
world_map.show()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D