P

Plotly Studio

Powerful skill for interactive, scientific, statistical, data. Includes structured workflows, validation checks, and reusable patterns for scientific.

SkillClipticsscientificv1.0.0MIT
0 views0 copies

Plotly Studio

Create interactive, publication-quality visualizations using Plotly's Python library. This skill covers Plotly Express for quick charts, Graph Objects for full customization, subplots, animations, and deploying interactive dashboards.

When to Use This Skill

Choose Plotly Studio when you need to:

  • Build interactive charts with hover tooltips, zoom, and pan capabilities
  • Create web-ready visualizations that users can explore dynamically
  • Generate animated charts showing data changes over time
  • Build dashboards with interconnected interactive plots

Consider alternatives when:

  • You need static publication figures with precise typographic control (use matplotlib)
  • You need statistical visualizations with minimal code (use Seaborn)
  • You need real-time streaming data visualizations (use Bokeh with server)

Quick Start

pip install plotly pandas kaleido
import plotly.express as px import pandas as pd # Quick interactive scatter plot df = px.data.gapminder() fig = px.scatter( df.query("year == 2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent", hover_name="country", log_x=True, title="GDP vs Life Expectancy (2007)" ) fig.show() # Save as interactive HTML fig.write_html("scatter.html") # Save as static image fig.write_image("scatter.png", scale=2)

Core Concepts

Plotly Express vs Graph Objects

FeaturePlotly Express (px)Graph Objects (go)
SyntaxOne-liner functionsVerbose, explicit
CustomizationGood defaults, limited controlFull control
Data inputDataFramesArrays, dicts
Best forQuick explorationPublication figures
Learning curveLowMedium-high

Common Chart Types

import plotly.express as px import plotly.graph_objects as go from plotly.subplots import make_subplots import pandas as pd import numpy as np # Line chart with multiple traces df = px.data.stocks() fig = px.line(df, x="date", y=df.columns[1:], title="Stock Prices Over Time") fig.update_layout(yaxis_title="Price (USD)") fig.show() # Heatmap with Graph Objects data = np.random.randn(10, 10) fig = go.Figure(data=go.Heatmap( z=data, colorscale="RdBu_r", zmid=0 )) fig.update_layout(title="Correlation Matrix") fig.show() # Multi-panel figure fig = make_subplots( rows=2, cols=2, subplot_titles=("Scatter", "Histogram", "Box", "Bar") ) fig.add_trace( go.Scatter(x=np.random.randn(100), y=np.random.randn(100), mode="markers"), row=1, col=1 ) fig.add_trace( go.Histogram(x=np.random.randn(500), nbinsx=30), row=1, col=2 ) fig.add_trace( go.Box(y=[np.random.randn(50) for _ in range(4)]), row=2, col=1 ) fig.add_trace( go.Bar(x=["A", "B", "C", "D"], y=[23, 45, 12, 38]), row=2, col=2 ) fig.update_layout(height=600, showlegend=False, title="Dashboard") fig.show()

Animated Visualizations

import plotly.express as px # Animated scatter plot over time df = px.data.gapminder() fig = 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], title="Gapminder: 50 Years of Global Development" ) fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = 500 fig.show()

Configuration

ParameterDescriptionDefault
templateVisual theme"plotly"
color_discrete_sequenceColor palette for categorical dataPlotly default
color_continuous_scaleColormap for continuous data"Viridis"
widthFigure width in pixels700
heightFigure height in pixels450
rendererDisplay backend"browser"

Best Practices

  1. Start with Plotly Express, customize with update_* — Build the basic chart with px functions, then refine with fig.update_layout(), fig.update_traces(), and fig.update_xaxes(). This gives you speed of Express with the customization of Graph Objects.

  2. Use hover_data to add context without clutter — Instead of adding more visual encodings (colors, sizes), put secondary information in hover tooltips with hover_data=["column1", "column2"]. This keeps the chart clean while making details accessible on demand.

  3. Export with kaleido for static images — Install kaleido for fig.write_image() support. Use scale=2 or scale=3 for high-DPI outputs. For vector formats, export as SVG or PDF rather than PNG for publication use.

  4. Set explicit axis ranges for animations — Animated charts with auto-scaling axes produce jarring jumps between frames. Set range_x and range_y to encompass the full data range across all animation frames.

  5. Use fig.update_layout(template="plotly_white") for clean presentations — The default template has a gray background. Switch to "plotly_white" or "simple_white" for cleaner figures suitable for reports and presentations.

Common Issues

Figures don't display in Jupyter — Plotly needs a renderer configured for your environment. Run import plotly.io as pio; pio.renderers.default = "notebook" for classic Jupyter, or "colab" for Google Colab. VSCode requires the Jupyter extension with "vscode" renderer.

Static image export failsfig.write_image() requires the kaleido package. Install with pip install kaleido. If kaleido fails on Linux servers, ensure you have required system libraries or use fig.write_html() and convert to image separately.

Large datasets make interactive charts slow — Plotly renders all data points client-side in the browser. For datasets over 10,000 points, use px.scatter(render_mode="webgl") for GPU-accelerated rendering, or downsample data before plotting. WebGL mode handles millions of points smoothly.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates