Data Visualization With Python Lab.-17007256038890 PDF
Data Visualization With Python Lab.-17007256038890 PDF
LABORATORY MANUAL
DATA VISUALIZATION WITH PYTHON
BCS358D
III Semester
Prepared by:
1. Gowtham Raj M
2. Sneha N P
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
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,
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
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.
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)
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)
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.
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
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.
# Sample data
categories = ['Category A', 'Category B', 'Category C', 'Category D']
values = [25, 40, 30, 35]
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
# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 12, 5, 20, 15]
# Add a legend
plt.legend()
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.
# Create a histogram
plt.hist(data, bins=20, color='skyblue', edgecolor='black')
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.
# Sample data
labels = ['Category A', 'Category B', 'Category C', 'Category D']
sizes = [30, 15, 45, 10]
colors = ['lightcoral', 'lightskyblue', 'lightgreen', 'lightpink']
# Adding a title
plt.title('Pie Chart Example')
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.
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 3, 8, 10]
# Add a legend
plt.legend()
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.
# Sample data
x = [1, 2, 3, 4, 5]
y1 = [2, 4, 6, 8, 10]
y2 = [1, 3, 5, 7, 9]
# Add a legend
plt.legend()
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.
# Sample data
tips = sns.load_dataset("tips")
# Add a legend
plt.legend(title="Time of Day")
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.
# Sample data
data = {
'Categories': ['Category A', 'Category B', 'Category C', 'Category D'],
'Values': [25, 40, 30, 35]
}
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)
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
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')
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
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()
Acharya Institute of Technology – Dept. of CS&E Data Visualization with Python Code: BCS358D