0% found this document useful (0 votes)
25 views4 pages

8-10 Python

Python vtu third semester lab manual

Uploaded by

ramya.ramya3805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

8-10 Python

Python vtu third semester lab manual

Uploaded by

ramya.ramya3805
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

10b )map using plotpy libraries

import plotly.express as px
import pandas as pd
data = {
'City': ['New York', 'Los Angeles',
'Chicago', 'Houston', 'Phoenix'],
'Latitude': [40.7128, 34.0522,
41.8781, 29.7604, 33.4484],
'Longitude': [-74.0060, -118.2437, -
87.6298, -95.3698, -112.0740]
}
df = pd.DataFrame(data)
fig = px.scatter_geo(df,
lat='Latitude',
lon='Longitude',
text='City', # Adds city
name as hover text
title='Cities in the United
States')
fig.show()
10a Time series using plotlib libraries
import plotly.express as px
import pandas as pd
from plotly.offline import plot
df = px.data.stocks()
fig = px.line(df,
x="date",
y=df.columns.drop("date"), # Drop 'date'
column from y-values
hover_data={"date": "|%b %d, %Y"})
fig.update_xaxes(title="Date", tickformat="%b %d,
%Y")
fig.update_layout(
title="Stock Prices Over Time",
xaxis_title="Date",
yaxis_title="Stock Price",
template="plotly_dark" # Optional theme
)
plot(fig)

pd.set_option("display.max_rows", None) # Show


all rows in the DataFrame
pd.set_option("display.max_columns", None)
print(df)
9)python program to draw 3D plot using plotly
Libraries
import pandas as pd
import plotly.graph_objects as go
import plotly.offline as pyo
data = {
'Animal': ['Dog', 'Cat', 'Elephant', 'Horse', 'Tiger', 'Rabbit', 'Monkey'],
'Lifespan': [12, 15, 60, 25, 20, 10, 30],
'Weight': [30, 5, 5000, 450, 200, 2, 40]
}
df = pd.DataFrame(data)
df.to_csv('Lifespan4.csv', index=False)
print("CSV file 'Lifespan4.csv' has been created!")
df = pd.read_csv('Lifespan4.csv')
print(df)
fig = go.Figure(data=[go.Scatter3d(
x=df['Animal'],
y=df['Lifespan'],
z=df['Weight'],
mode='markers'
)])
fig.update_layout(
scene=dict(
xaxis_title='Animal',
yaxis_title='Lifespan',
zaxis_title='Weight'
),
title='Animal X Lifespan X Weight'
)
pyo.plot(fig)
8) Sine and Cosine Wave
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
y2 = np.cos(x)
plt.figure(figsize=(8, 6))
plt.plot(x, y1, label='Sine wave', color='blue',
linestyle='-', linewidth=2, marker='o',
markersize=5, markerfacecolor='red',
markeredgewidth=2)
plt.plot(x, y2, label='Cosine wave',
color='green', linestyle='--', linewidth=2,
marker='X', markersize=7,
markerfacecolor='yellow',
markeredgewidth=3)
plt.title("Linear Plotting with Line Formatting",
fontsize=16)
plt.xlabel("X-axis", fontsize=12)
plt.ylabel("Y-axis", fontsize=12)
plt.legend()
plt.grid(True)
plt.show()

You might also like