Plotly

From aipoch/medical-research-skills · View interactive version

Plotly is an AI agent skill from the GitHub repository aipoch/medical-research-skills. Interactive visualization library for Python. Use it when you need hover tooltips, zoom/pan, selection, animations, or charts embeddable in web pages (e.g., dashboards, exploratory analysis, presentations).

How to use this skill

Skill file

Source: https://github.com/aipoch/medical-research-skills

Plotly

When to Use

Key Features

Dependencies

Example Usage

Skill directory: 20260316/scientific-skills/Others/plotly
No packaged executable script was detected.
Use the documented workflow in SKILL.md together with the references/assets in this folder.

Example run plan:

  1. Read the skill instructions and collect the required inputs.
  2. Follow the documented workflow exactly.
  3. Use packaged references/assets from this folder when the task needs templates or rules.
  4. Return a structured result tied to the requested deliverable.

Implementation Details

1. When to Use

Use Plotly when you need interactive, shareable visualizations, especially in these scenarios:

If you only need static publication figures, consider Matplotlib or other scientific visualization tools.

2. Key Features

Reference guides (optional reading):

3. Dependencies

4. Example Usage

A complete runnable example demonstrating: Plotly Express + Graph Objects updates, hover customization, subplots, and export.

Install

uv pip install "plotly>=5.0" "pandas>=1.5" "kaleido>=0.2"

Run

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots

def main():
    # Sample dataset
    df = pd.DataFrame(
        {
            "x": [1, 2, 3, 4, 5],
            "y": [10, 11, 12, 11.5, 13],
            "group": ["A", "A", "B", "B", "B"],
        }
    )

    # 1) Quick chart with Plotly Express
    fig_scatter = px.scatter(
        df,
        x="x",
        y="y",
        color="group",
        title="Scatter (px) + Graph Objects Updates",
        template="plotly_white",
    )

    # 2) Use Graph Objects methods on a px figure
    fig_scatter.update_traces(
        hovertemplate="x=%{x}<br>y=%{y:.2f}<br>group=%{marker.color}<extra></extra>"
    )
    fig_scatter.add_hline(y=11, line_dash="dash", line_color="gray")

    # 3) Build a small dashboard-like layout with subplots
    fig = make_subplots(
        rows=1,
        cols=2,
        subplot_titles=("Interactive Scatter", "Group Means (Bar)"),
        specs=[[{"type": "scatter"}, {"type": "bar"}]],
    )

    # Left: reuse traces from the px figure
    for tr in fig_scatter.data:
        fig.add_trace(tr, row=1, col=1)

    # Right: bar chart with group means
    means = df.groupby("group", as_index=False)["y"].mean()
    fig.add_trace(
        go.Bar(x=means["group"], y=means["y"], name="mean(y)"),
        row=1,
        col=2,
    )

    fig.update_layout(
        title="Plotly End-to-End Example",
        height=450,
        legend_title_text="Group",
        margin=dict(l=40, r=20, t=70, b=40),
    )

    # Show interactively (notebook or supported environment)
    fig.show()

    # Export
    fig.write_html("plotly_example.html", include_plotlyjs="cdn")
    fig.write_image("plotly_example.png")  # requires kaleido

if __name__ == "__main__":
    main()

5. Implementation Details

API choice: `px` vs `go`

Interactivity configuration

Export behavior

When Not to Use

Required Inputs

Recommended Workflow

  1. Validate the request against the skill boundary and confirm all required inputs are present.
  2. Select the documented execution path and prefer the simplest supported command or procedure.
  3. Produce the expected output using the documented file format, schema, or narrative structure.
  4. Run a final validation pass for completeness, consistency, and safety before returning the result.

Output Contract

Validation and Safety Rules

Failure Handling

Quick Validation

Run this minimal verification path before full execution when possible:

No local script validation step is required for this skill.

Expected output format:

Result file: plotly_result.md
Validation summary: PASS/FAIL with brief notes
Assumptions: explicit list if any
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.