Data Visualization Python
Data Visualization Python
PROGRAM 1
a) Write a python program to find the best of two test average marks out of three
test’s marks acceptedfrom the user.
SOURCE CODE
# take inputs
num1 = float(input('Enter first number: '))
num2 = float(input('Enter second number: '))
num3 = float(input('Enter third number: '))
# calculate average
avg = (num1 + num2 + num3)/3
# display result
print('The average of numbers = %0.2f' %avg)
OUTPUT
Enter first number: 10
Enter second number: 2
Enter third number: 30
The average of numbers = 14.00
SOURCE CODE
if value == value[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
counted_dict = Counter(value)
for key in sorted(counted_dict.keys()):
print(f'{key} appears {counted_dict[key]} times');
OUTPUT
Enter a value : 11
Palindrome
1 appears 2 times
PROGRAM 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 for input value is not followed.
SOURCE CODE
def fn(n):
if n == 1:
return 0
elif n == 2:
return 1
else:
return fn(n-1) + fn(n-2)
num = int(input("enter a number: "))
if num > 0:
print("fn(",num,") = ",fn(num),sep ="")
else:
print("error in input")
OUTPUT
Enter a number : 6
fn(6) = 5
Enter a number : -3
Input should be greater than 0
SOURCE CODE
def BinToDec(b):
return int(b,2)
def OctToHex(o):
return hex(int(o,8))
bnum = input("enter the binary number: ")
dnum = BinToDec(bnum)
print("\nEquivalent Decimal value = ",dnum)
OUTPUT
PROGRAM 3
A) Write a Python program that accepts a sentence and find the number of
words,digits, uppercase letters and lowercase letters.
SOURCE CODE
for ch in sentence:
if '0' <= ch <= '9':
digCnt += 1
elif 'A' <= ch <= 'Z':
upCnt += 1
elif 'a' <= ch <= 'z':
loCnt += 1
OUTPUT
enter a sentence :
John went to market
This sentence has 4 words
This sentence has 0 digits 1 upper case letters 16 lower case letters
B) Write a Python program to find the string similarity between two given strings
SOURCE CODE
match_count = 0
for i in range(short_string_length):
if str1[i] == str2[i]:
match_count += 1
OUTPUT
Enter String 1
HAPPY
Enter String 2
GOOGLE
Similarity between two said strings:
0.0
PROGRAM 4
A) Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib.
SOURCE CODE
import matplotlib.pyplot as plt
OUTPUT
B) Write a Python program to Demonstrate how to Draw a Scatter Plot using Matplotlib
SOURCE CODE
# Add colorbar
plt.colorbar(scatter, label='Index')
OUTPUT
PROGRAM 5
A) Write a Python program to Demonstrate how to Draw a Histogram Plot using Matplotlib.
SOURCE CODE
OUTPUT
B) Write a Python program to Demonstrate how to Draw a Pie Chart using Matplotlib.
SOURCE CODE
# Add title
plt.title('FIFA World Cup Wins by Country')
OUTPUT
PROGRAM 6
A)Write a Python program to illustrate Linear Plotting using Matplotlib.
SOURCE CODE
OUTPUT
B)Write a Python program to illustrate liner plotting with line formatting using Matplotlib.
SOURCE CODE
OUTPUT
PROGRAM 7
A) Write a Python program which explains uses of customizing seaborn plots with Aesthetic
functions.
SOURCE CODE
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def sinplot(n=10):
x = np.linspace(0, 14, 100)
for i in range(1, n + 1):
plt.plot(x, np.sin(x + i * .5) * (n + 2 - i))
sns.set_theme()
#sns.set_context("talk")
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
sinplot()
plt.title('Seaborn plots with Aesthetic functions')
plt.show()
OUTPUT
PROGRAM 8
Write a Python program to explain working with bokeh line graph using Annotations and
Legends.
a)Write a Python program for plotting different types of plots using Bokeh.
import numpy as np
TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"
p1.circle(x, y, legend_label="sin(x)")
p1.circle(x, 2*y, legend_label="2*sin(x)", color="orange")
p1.circle(x, 3*y, legend_label="3*sin(x)", color="green")
p1.legend.title = 'Markers'
p2.circle(x, y, legend_label="sin(x)")
p2.line(x, y, legend_label="sin(x)")
p2.legend.title = 'Lines'
OUTPUT
PROGRAM 9
Write a Python program to draw 3D Plots using Plotly Libraries.
import plotly.express as px
df = px.data.gapminder().query("continent=='Asia'")
fig = px.line_3d(df, x="gdpPercap", y="pop", z="year", color='country', title='Economic
Evolution of Asian Countries Over Time')
fig.show()
OUTPUT
PROGRAM 10
A)Write a Python program to draw Time Series using Plotly Libraries.
import pandas as pd
import plotly.express as px
dollar_conv = pd.read_csv('CUR_DLR_INR.csv')
import plotly.express as px
import pandas as pd