{"spec_id":"box-horizontal","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nbox-horizontal: Horizontal Box Plot\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 91/100 | Updated: 2026-05-12\n\"\"\"\n\nimport os\n\nimport numpy as np\nimport pandas as pd\nimport plotly.graph_objects as go\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nGRID = \"rgba(26,26,23,0.10)\" if THEME == \"light\" else \"rgba(240,239,232,0.10)\"\n\nIMPRINT = [\"#009E73\", \"#C475FD\", \"#4467A3\", \"#BD8233\", \"#AE3030\", \"#2ABCCD\"]\n\n# Data - Response times (ms) by service type\nnp.random.seed(42)\n\nservices = [\"Database Query\", \"API Gateway\", \"Authentication\", \"File Storage\", \"Cache Lookup\", \"Message Queue\"]\n\n# Generate data with different distributions for each service\ndata = []\ndistributions = [\n    (120, 40, 15),  # Database Query - higher, more spread\n    (85, 25, 8),  # API Gateway - medium\n    (45, 15, 5),  # Authentication - fast, tight\n    (200, 80, 20),  # File Storage - slow, very spread, many outliers\n    (15, 5, 3),  # Cache Lookup - very fast\n    (65, 30, 10),  # Message Queue - medium with spread\n]\n\nfor service, (mean, std, n_outliers) in zip(services, distributions):\n    n = 100\n    values = np.random.normal(mean, std, n)\n    # Add some outliers\n    outliers = np.random.normal(mean + 3 * std, std / 2, n_outliers)\n    all_values = np.concatenate([values, outliers])\n    # Ensure positive values (response times can't be negative)\n    all_values = np.maximum(all_values, 5)\n    for v in all_values:\n        data.append({\"Service\": service, \"Response Time (ms)\": v})\n\ndf = pd.DataFrame(data)\n\n# Sort services by median response time for easier comparison\nmedian_order = df.groupby(\"Service\")[\"Response Time (ms)\"].median().sort_values()\nservices_sorted = median_order.index.tolist()\n\n# Create figure with horizontal box plots\nfig = go.Figure()\n\nfor i, service in enumerate(services_sorted):\n    service_data = df[df[\"Service\"] == service][\"Response Time (ms)\"]\n    fig.add_trace(\n        go.Box(\n            x=service_data,\n            name=service,\n            orientation=\"h\",\n            marker=dict(color=IMPRINT[i % len(IMPRINT)], size=8, outliercolor=IMPRINT[i % len(IMPRINT)]),\n            line=dict(color=IMPRINT[i % len(IMPRINT)], width=2),\n            fillcolor=IMPRINT[i % len(IMPRINT)],\n            opacity=0.7,\n            boxmean=False,\n            hovertemplate=\"<b>%{name}</b><br>Value: %{x:.1f} ms<extra></extra>\",\n        )\n    )\n\n# Layout\nfig.update_layout(\n    title=dict(text=\"box-horizontal · plotly · anyplot.ai\", font=dict(size=28, color=INK), x=0.5, xanchor=\"center\"),\n    xaxis=dict(\n        title=dict(text=\"Response Time (ms)\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        gridcolor=GRID,\n        gridwidth=1,\n        linecolor=INK_SOFT,\n        zerolinecolor=INK_SOFT,\n    ),\n    yaxis=dict(\n        title=dict(text=\"Service Type\", font=dict(size=22, color=INK)),\n        tickfont=dict(size=18, color=INK_SOFT),\n        linecolor=INK_SOFT,\n    ),\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    showlegend=False,\n    margin=dict(l=180, r=50, t=80, b=80),\n    font=dict(color=INK),\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=1600, height=900, scale=3)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}