{"spec_id":"parallel-basic","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nparallel-basic: Basic Parallel Coordinates Plot\nLibrary: plotly 6.9.0 | Python 3.13.14\nQuality: 89/100 | Updated: 2026-07-24\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\"\n\n\n# Imprint palette discrete colorscale: Setosa=#009E73, Versicolor=#C475FD, Virginica=#4467A3\n# Kept fully opaque (no alpha blending) so hues stay pixel-identical between themes —\n# translucency would composite against PAGE_BG, which differs between light and dark.\nIMPRINT_COLORSCALE = [\n    [0.0, \"#009E73\"],\n    [0.33, \"#009E73\"],\n    [0.33, \"#C475FD\"],\n    [0.67, \"#C475FD\"],\n    [0.67, \"#4467A3\"],\n    [1.0, \"#4467A3\"],\n]\n\n# Data - Iris-like dataset for multivariate demonstration\nnp.random.seed(42)\nn_per_species = 50\n\nsetosa = pd.DataFrame(\n    {\n        \"sepal_length\": np.random.normal(5.0, 0.35, n_per_species),\n        \"sepal_width\": np.random.normal(3.4, 0.38, n_per_species),\n        \"petal_length\": np.random.normal(1.5, 0.17, n_per_species),\n        \"petal_width\": np.random.normal(0.25, 0.11, n_per_species),\n        \"species\": \"setosa\",\n    }\n)\n\nversicolor = pd.DataFrame(\n    {\n        \"sepal_length\": np.random.normal(5.9, 0.52, n_per_species),\n        \"sepal_width\": np.random.normal(2.8, 0.31, n_per_species),\n        \"petal_length\": np.random.normal(4.3, 0.47, n_per_species),\n        \"petal_width\": np.random.normal(1.3, 0.20, n_per_species),\n        \"species\": \"versicolor\",\n    }\n)\n\nvirginica = pd.DataFrame(\n    {\n        \"sepal_length\": np.random.normal(6.6, 0.64, n_per_species),\n        \"sepal_width\": np.random.normal(3.0, 0.32, n_per_species),\n        \"petal_length\": np.random.normal(5.6, 0.55, n_per_species),\n        \"petal_width\": np.random.normal(2.0, 0.27, n_per_species),\n        \"species\": \"virginica\",\n    }\n)\n\ndf = pd.concat([setosa, versicolor, virginica], ignore_index=True)\nspecies_map = {\"setosa\": 0, \"versicolor\": 1, \"virginica\": 2}\ndf[\"species_code\"] = df[\"species\"].map(species_map)\n\n# Plot\nfig = go.Figure(\n    data=go.Parcoords(\n        line={\n            \"color\": df[\"species_code\"],\n            \"colorscale\": IMPRINT_COLORSCALE,\n            \"showscale\": True,\n            \"cmin\": 0,\n            \"cmax\": 2,\n            \"colorbar\": {\n                \"title\": {\"text\": \"Species\", \"font\": {\"size\": 12, \"color\": INK}},\n                \"tickvals\": [0, 1, 2],\n                \"ticktext\": [\"Setosa\", \"Versicolor\", \"Virginica\"],\n                \"tickfont\": {\"size\": 10, \"color\": INK_SOFT},\n                \"len\": 0.6,\n                \"y\": 0.5,\n                \"bgcolor\": ELEVATED_BG,\n                \"bordercolor\": INK_SOFT,\n                \"borderwidth\": 1,\n            },\n        },\n        dimensions=[\n            {\"label\": \"Sepal Length (cm)\", \"values\": df[\"sepal_length\"], \"range\": [4, 8]},\n            {\"label\": \"Sepal Width (cm)\", \"values\": df[\"sepal_width\"], \"range\": [2, 4.5]},\n            {\"label\": \"Petal Length (cm)\", \"values\": df[\"petal_length\"], \"range\": [0.5, 7]},\n            {\"label\": \"Petal Width (cm)\", \"values\": df[\"petal_width\"], \"range\": [0, 2.8]},\n        ],\n        labelfont={\"size\": 12, \"color\": INK},\n        tickfont={\"size\": 10, \"color\": INK_SOFT},\n        rangefont={\"size\": 10, \"color\": INK_SOFT},\n    )\n)\n\nfig.update_layout(\n    autosize=False,\n    width=800,\n    height=450,\n    title={\n        \"text\": \"parallel-basic · python · plotly · anyplot.ai\",\n        \"subtitle\": {\n            \"text\": \"Setosa (green) clusters tightly at low petal dimensions\"\n            \" — clearly separated from Versicolor and Virginica\",\n            \"font\": {\"size\": 12, \"color\": INK_SOFT},\n        },\n        \"font\": {\"size\": 16, \"color\": INK},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n        \"y\": 0.97,\n    },\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    font={\"color\": INK},\n    margin={\"l\": 80, \"r\": 110, \"t\": 110, \"b\": 60},\n)\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=800, height=450, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}