Visualización con plotly
Contenido
Visualización con plotly¶
pip install plotly==5.6.0
conda install -c plotly plotly=5.6.0
import plotly.express as px
import pandas as pd
df = px.data.tips()
fig = px.scatter(
df, x='total_bill', y='tip', opacity=0.65,
trendline='ols', trendline_color_override='darkblue'
)
fig.show()
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = px.line(df, x='Date', y='AAPL.High', title='Time Series with Rangeslider')
fig.update_xaxes(rangeslider_visible=True)
fig.show()
df = px.data.gapminder()
px.scatter(df, x="gdpPercap", y="lifeExp", animation_frame="year", animation_group="country",
size="pop", color="continent", hover_name="country",
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import numpy as np
# Initialize figure with 4 3D subplots
fig = make_subplots(
rows=2, cols=2,
specs=[[{'type': 'surface'}, {'type': 'surface'}],
[{'type': 'surface'}, {'type': 'surface'}]])
# Generate data
x = np.linspace(-5, 80, 10)
y = np.linspace(-5, 60, 10)
xGrid, yGrid = np.meshgrid(y, x)
z = xGrid ** 3 + yGrid ** 3
# adding surfaces to subplots.
fig.add_trace(
go.Surface(x=x, y=y, z=z, colorscale='Viridis', showscale=False),
row=1, col=1)
fig.add_trace(
go.Surface(x=x, y=y, z=z, colorscale='RdBu', showscale=False),
row=1, col=2)
fig.add_trace(
go.Surface(x=x, y=y, z=z, colorscale='YlOrRd', showscale=False),
row=2, col=1)
fig.add_trace(
go.Surface(x=x, y=y, z=z, colorscale='YlGnBu', showscale=False),
row=2, col=2)
fig.update_layout(
title_text='3D subplots with different colorscales',
height=800,
width=800
)
fig.show()