1.6.5kata 5 de 5
Plotly: Interactivo y web-native
Zoom, hover, web-ready, exporta a HTML
Plotly es interactivo y web-native: zoom, pan, hover para ver valores, desseleccionar series con click. `px.scatter()` es API alto nivel (similar a Seaborn), `go.Figure()` es API bajo nivel (control total). Plotly genera HTML que puedes compartir sin dependencias. Para reportes interactivos y dashboards, Plotly es superior.
structure.txt
import plotly.express as px
import plotly.graph_objects as go
# High-level API
fig = px.scatter(df, x='age', y='salary', color='dept')
fig.show() # interactive in browser
# Low-level API (full control)
fig = go.Figure()
for dept in df['dept'].unique():
dept_df = df[df['dept'] == dept]
fig.add_trace(go.Scatter(x=dept_df['age'], y=dept_df['salary'],
mode='markers', name=dept))
fig.update_layout(title='Salary vs Age')
fig.show()
# Save as HTML to share
fig.write_html('interactive_plot.html')Debugging lab
Detecta y corrige el error en el código.
0/1 tests passing0%
- 01
# Static matplotlib plot for stakeholder