0% found this document useful (0 votes)
19 views

python prog sh

Python Codes for VTU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

python prog sh

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

8a)

import numpy as np
from bokeh.plotting import figure, show
from bokeh.layouts import gridplot

x = np.linspace(0, 4 * np.pi, 100)


y = np.sin(x)

TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"

# Create two plots


p1 = figure(title="Example 1", tools=TOOLS, width=400, height=400)
p1.circle(x, y, legend_label="sin(x)", size=8)
p1.circle(x, 2 * y, legend_label="2*sin(x)", color="orange", size=8)
p1.circle(x, 3 * y, legend_label="3*sin(x)", color="green", size=8)
p1.legend.title = 'Marker'

p2 = figure(title="Example 2", tools=TOOLS, width=400, height=400)


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",
line_width=2)
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'

# Show both plots side by side


show(gridplot([[p1, p2]]))

8b)

import pandas as pd
import numpy as np
from bokeh.plotting import figure, output_file, show
from bokeh.layouts import gridplot

# Load data
tips = pd.read_csv("tips.csv")

# Output file
output_file("bokeh_tips_plots.html")

# Create Histogram
hist, edges = np.histogram(tips['total_bill'], bins=8)
hist_plot = figure(title="Histogram of Total Bill")
hist_plot.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="purple")

# Create Bar Plot


avg_bill = tips.groupby('day')['total_bill'].mean()
bar_plot = figure(title="Average Total Bill per Day", x_range=list(avg_bill.index))
bar_plot.vbar(x=avg_bill.index, top=avg_bill, width=0.5, color="orange")

# Create Scatter Plot


scatter_plot = figure(title="Total Bill vs Tip")
scatter_plot.scatter(x=tips['total_bill'], y=tips['tip'], size=8, color="green",
alpha=0.6)

# Combine and show


show(gridplot([[hist_plot, bar_plot], [scatter_plot]]))

9)
import plotly.graph_objects as go
import pandas as pd

# Load the tips dataset


tips = pd.read_csv("tips.csv")

# Create the 3D scatter plot and set layout in one step


fig = go.Figure(go.Scatter3d(
x=tips['total_bill'],
y=tips['tip'],
z=tips['size'],
mode='markers',
marker=dict(size=8, color=tips['size'], colorscale='Viridis', opacity=0.8)
))

# Update layout
fig.update_layout(
scene=dict(
xaxis_title='Total Bill', yaxis_title='Tip', zaxis_title='Size'
),
title='3D Scatter Plot with Tips Dataset'
)

# Save and show the plot


fig.write_html("3d_scatter_plot_tips.html")
fig.show()

10 a)
import pandas as pd
import plotly.express as px
dollar_conv = pd.read_csv('CUR_DLR_INR (1).csv')
fig = px.line(dollar_conv, x='DATE', y='RATE', title='Dollar vs Rupee')
fig.show()

10 b)

import plotly.express as px
import pandas as pd

data = pd.read_csv('gapminder_with_codes.csv')

# Create basic choropleth map

fig = px.choropleth(data, locations='iso_alpha',


color='gdpPercap',hover_name='country', projection='natural earth', title='GDP per
Capita by Country')

fig.show()

You might also like