{"spec_id":"scatter-color-mapped","library":"altair","language":"python","code":"\"\"\" anyplot.ai\nscatter-color-mapped: Color-Mapped Scatter Plot\nLibrary: altair 6.1.0 | Python 3.13.13\nQuality: 95/100 | Updated: 2026-05-08\n\"\"\"\n\nimport os\n\nimport altair as alt\nimport numpy as np\nimport pandas as pd\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\nELEVATED_BG = \"#FFFDF6\" if THEME == \"light\" else \"#242420\"\n\n# Data - simulate temperature readings at geographic locations\nnp.random.seed(42)\nn_points = 150\n\n# Create spatial coordinates with clustered patterns\nx = np.concatenate([np.random.normal(20, 8, 50), np.random.normal(60, 10, 50), np.random.normal(40, 12, 50)])\ny = np.concatenate([np.random.normal(30, 8, 50), np.random.normal(70, 10, 50), np.random.normal(50, 15, 50)])\n\n# Third variable: intensity/temperature that correlates with position\nintensity = 0.3 * x + 0.5 * y + np.random.normal(0, 8, n_points)\nintensity = (intensity - intensity.min()) / (intensity.max() - intensity.min()) * 100\n\ndf = pd.DataFrame({\"X Position\": x, \"Y Position\": y, \"Intensity\": intensity})\n\n# Create color-mapped scatter plot\nchart = (\n    alt.Chart(df)\n    .mark_circle(size=200, opacity=0.8, strokeWidth=1.0, stroke=PAGE_BG)\n    .encode(\n        x=alt.X(\"X Position:Q\", title=\"X Position (units)\", scale=alt.Scale(nice=True)),\n        y=alt.Y(\"Y Position:Q\", title=\"Y Position (units)\", scale=alt.Scale(nice=True)),\n        color=alt.Color(\n            \"Intensity:Q\",\n            title=\"Intensity (a.u.)\",\n            scale=alt.Scale(scheme=\"viridis\"),\n            legend=alt.Legend(\n                titleFontSize=18, labelFontSize=16, symbolSize=200, gradientLength=300, gradientThickness=20\n            ),\n        ),\n        tooltip=[\"X Position:Q\", \"Y Position:Q\", \"Intensity:Q\"],\n    )\n    .properties(\n        width=1600,\n        height=900,\n        title=alt.Title(\"scatter-color-mapped · altair · anyplot.ai\", fontSize=28, anchor=\"middle\"),\n        background=PAGE_BG,\n    )\n    .configure_axis(\n        labelFontSize=18,\n        titleFontSize=22,\n        gridOpacity=0.1,\n        domainColor=INK_SOFT,\n        tickColor=INK_SOFT,\n        gridColor=INK,\n        labelColor=INK_SOFT,\n        titleColor=INK,\n    )\n    .configure_view(stroke=INK_SOFT, strokeWidth=0, fill=PAGE_BG)\n    .configure_title(color=INK)\n    .configure_legend(fillColor=ELEVATED_BG, strokeColor=INK_SOFT, labelColor=INK_SOFT, titleColor=INK)\n)\n\n# Save as PNG and HTML (4800 x 2700 px with scale_factor=3)\nchart.save(f\"plot-{THEME}.png\", scale_factor=3.0)\nchart.save(f\"plot-{THEME}.html\")\n"}