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

Visualizing Data with Plotly and Matplotlib

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)
7 views4 pages

Visualizing Data with Plotly and Matplotlib

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 [Link] 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 = [Link](data)
fig = px.scatter_geo(df,
lat='Latitude',
lon='Longitude',
text='City', # Adds city
name as hover text
title='Cities in the United
States')
[Link]()
10a Time series using plotlib libraries
import [Link] as px
import pandas as pd
from [Link] import plot
df = [Link]()
fig = [Link](df,
x="date",
y=[Link]("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 [Link] 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 = [Link](data)
df.to_csv('[Link]', index=False)
print("CSV file '[Link]' has been created!")
df = pd.read_csv('[Link]')
print(df)
fig = [Link](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'
)
[Link](fig)
8) Sine and Cosine Wave
import [Link] as plt
import numpy as np
x = [Link](0, 10, 100)
y1 = [Link](x)
y2 = [Link](x)
[Link](figsize=(8, 6))
[Link](x, y1, label='Sine wave', color='blue',
linestyle='-', linewidth=2, marker='o',
markersize=5, markerfacecolor='red',
markeredgewidth=2)
[Link](x, y2, label='Cosine wave',
color='green', linestyle='--', linewidth=2,
marker='X', markersize=7,
markerfacecolor='yellow',
markeredgewidth=3)
[Link]("Linear Plotting with Line Formatting",
fontsize=16)
[Link]("X-axis", fontsize=12)
[Link]("Y-axis", fontsize=12)
[Link]()
[Link](True)
[Link]()

You might also like