DV Nivas
DV Nivas
Submitted By
NIVAS B L (22BBTCD040)
Prof. LATHASHREE P V
CMR University
(Lakeside Campus)
Off Hennur - Bagalur Main Road,
Near Kempegowda International Airport, Chagalahatti,Bengaluru, Karnataka-562149,
Academic Year 2023-
2024
1
TABLE OF CONTENT
SI.No Program Name Page Number
20 Write a Python program for creating Maps using Plotly Libraries. 23-24
2
1. Write a python program to visualize the data in Line Plots.
Line Plots: A line plot is used to represent quantitative values over a continuous interval or
time period. It is generally used to depict trends on how the data has changed over time.
3
2) Write a python program to visualize the data in Area Plots.
Area Plots: An Area Plot is also called as Area Chart which is used to display magnitude and
proportion of multiple variables.
days = [1, 2, 3, 4, 5]
sleeping = [8, 7, 6, 9, 8]
eating = [3, 4, 3, 3, 4]
working = [6, 7, 8, 5, 6]
playing = [7, 8, 6, 7, 9]
4
3) Write a python program to visualize the data in Histogram Plots.
Histograms: Histograms represents the frequency distribution of a dataset. It is a graph
showing the number of observations within each given interval.
population_age = [18, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]
bins = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
plt.show()
5
4) Write a python program to visualize the data in Bar Plots.
A Bar chart or bar graph is a chart or graph that presents categorical data with rectangular bars
with heights or lengths proportional to the values that they represent. A bar plot is a way of
representing data where the length of the bars represents the magnitude/size of the
feature/variable.
from matplotlib import pyplot as plt
bmw_distances = [60, 70, 50, 40, 30]
audi_distances = [70, 60, 40, 50, 80]
plt.bar([0.25, 1.25, 2.25, 3.25, 4.25], bmw_distances, label="BMW", width=0.5)
plt.bar([0.75, 1.75, 2.75, 3.75, 4.75], audi_distances, label="Audi", color='m',
width=0.5)
plt.legend()
plt.xlabel('Days')
plt.ylabel('Distance (kms)')
plt.title('Information')
plt.show()
6
5) Write a python program to visualize the data in Pie Chart .
Pie Charts:
A Pie chart is a circular statistical chart, which is divided into sectors to illustrate numerical
proportion
7
6) Write a python program to visualize the data in Scatter Plots.
Scatter Plots:
A Scatter chart, also called a scatter plot, is a chart that shows the relationship between two
variables.
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5, 6, 7]
y = [10, 15, 20, 25, 30, 35, 40]
x1 = [2, 3, 4, 5, 6, 7, 8]
y1 = [5, 10, 15, 20, 25, 30, 35]
plt.scatter(x, y, label='High Income Low Saving', color='r')
plt.scatter(x1, y1, label='Low Income High Saving', color='b')
plt.xlabel('Saving (in thousands)')
plt.ylabel('Income (in thousands)')
plt.title('Scatter Plot')
plt.legend()
8
7) Write a Python program to illustrate Pie plotting with line formatting using
Matplotlib.
9
8) Write a Python program which explains uses of customizing seaborn plots
with Aesthetic functions.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def sinplot(n=10, amplitude=1, phase_shift=0.5, frequency=1):
x = np.linspace(0, 14, 100)
for i in range(1, n + 1):
plt.plot(x, amplitude * np.sin(frequency * (x + i *
phase_shift)) * (n + 2 - i))
sns.set_theme()
sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 2.5})
sinplot(n=8, amplitude=2, phase_shift=0.3, frequency=1.5)
plt.title('Seaborn Plots with Aesthetic Functions')
plt.grid(True)
plt.show()
10
9) Write a Python program to explain working with Bokeh line graph using
Annotations
and Legends.
11
plt.figure(figsize=(10, 10))
plot_data(guinea_data, "Guinea", "Confirmed Ebola Deaths")
plot_data(sierra_data, "Sierra Leone","Confirmed Ebola
Deaths") plot_data (liberia_data, "Liberia", "Confirmed
Ebola Deaths") plt.xlabel('Date', fontsize=18)
plt.ylabel( 'Number of Ebola Deaths',
fontsize=18) plt. title("Confirmed Ebola
Deaths",fontsize=20) plt.legend(loc=2)
plt.show()
if name == ' main ':
main()
12
10) Write a Python program for plotting different types of plots using Bokeh.
import numpy as np
from bokeh.layouts import gridplot
from bokeh.plotting import figure, show
import matplotlib.pyplot as
plt x = np.linspace(0,
4*np.pi, 100) y = np.sin(x)
p2 = figure(title="Example 2",
tools=TOOLS) p2.circle(x, y,
legend_label="sin(x)") p2.line(x, y,
legend_label="sin(x)")
p2.line(x, 2*y, legend_label="2*sin(x)", line_dash=(4, 4),
line_color="orange", lin p2.square(x, 3*y, legend_label="3*sin(x)",
fill_color=None, line_color="green") p2.line(x, 3*y, legend_label="3*sin(x)",
line_color="green")
p2.legend.title = 'Lines'
13
11) Write a Python program to Demonstrate how to Draw a Bar Plot using Matplotlib
14
12) Write a Python program to Demonstrate how to draw a Scatter Plot using
Matplotlib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Importing data.
cars_data = pd.read_csv(r"C:\Users\ksvra\Downloads\Toyota.csv")
15
13) Write a Python program to Demonstrate how to draw a Histogram using Matplotlib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
cars_data = pd.read_csv(r"C:\Users\ksvra\Downloads\Cars.csv")
16
14) Write a Python program to Demonstrate how to draw a Histogram using
Matplotlib
# Import libraries
import matplotlib.pyplot as plt
import pandas as pd
# Creating dataset
cars_data = pd.read_csv(r"C:
\Users\ksvra\Downloads\Car_sales.csv") cars =
cars_data["Manufacturer"].head(10)
data = cars_data["Sales in thousands"].head(10)
# Creating plot
fig = plt.figure(figsize =(10, 7))
plt.pie(data, labels=cars)
# show plot
17
15) Write a Python program to illustrate Linear Plotting using Matplotlib
def linear_plot():
# Sample data
x = [1, 2, 3, 4, 5]
y = [3, 7, 9, 11, 14]
18
16) Write a Python program to illustrate liner plotting with line formatting using
Matplotlib
def formatted_linear_plot():
# Sample data
x = [1, 2, 3, 4, 5, 6]
y = [3, 7, 9, 11, 14, 18]
19
17) Write a Python program liner plotting with line formatting using Matplotlib
20
18) Write a Python program to explain working with bokeh line graph using Annotations an
Legends.
from bokeh.plotting import figure, output_file, show
from bokeh.models import Label
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Create a figure
p = figure(title="Bokeh Line Graph with Annotations", x_axis_label='X-axis', y_axis
# Add an annotation
annotation = Label(x=3, y=6, text="Important Point", text_font_size="10pt", text_co
p.add_layout(annotation)
# Add legend
p.legend.location = "top_left"
p.legend.click_policy = "hide"
21
19) Write a Python program for plotting different types of plots using Bokeh
import pandas as pd
import numpy as np
from bokeh.plotting import figure, output_file, show
from bokeh.layouts import gridplot
# Histogram
hist, edges = np.histogram(tips['total_bill'], bins=8)
hist_plot = figure(title="Histogram of Total Bill",
x_axis_label='Total Bill', y_ax hist_plot.quad(top=hist, bottom=0,
left=edges[:-1], right=edges[1:], fill_color="pu
# Bar Plot
day_categories = tips['day'].unique()
average_total_bill = tips.groupby('day')['total_bill'].mean()
bar_plot = figure(title="Average Total Bill per Day",
x_axis_label='Day', y_axis_la x_range=day_categories)
bar_plot.vbar(x=day_categories, top=average_total_bill, width=0.5,
color="orange")
# Scatter Plot
scatter_plot = figure(title="Scatter Plot of Total Bill vs Tip",
x_axis_label='Tota
22
23
20) Write a Python program for creating Maps using Plotly Libraries.
import plotly.express as px
# Create a map
fig = px.scatter_geo(data, lat='Lat', lon='Lon', text='City',
size='Population', projection='natural earth',
title='Population of Cities')
24