8-10 Python
8-10 Python
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)