惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
TaoSecurity Blog
TaoSecurity Blog
Schneier on Security
Schneier on Security
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Project Zero
Project Zero
O
OpenAI News
W
WeLiveSecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Hacker News: Front Page
Cisco Talos Blog
Cisco Talos Blog
Spread Privacy
Spread Privacy
Help Net Security
Help Net Security
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
S
Security @ Cisco Blogs
Latest news
Latest news
AWS News Blog
AWS News Blog
U
Unit 42
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
博客园 - 司徒正美
B
Blog RSS Feed
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
D
Docker
Google Online Security Blog
Google Online Security Blog
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
月光博客
月光博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
SegmentFault 最新的问题
NISL@THU
NISL@THU
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Attack and Defense Labs
Attack and Defense Labs
小众软件
小众软件

MarkTechPost

A Coding Implementation of End-to-End Brain Decoding from MEG Signals Using NeuralSet and Deep Learning for Predicting Linguistic Features Meta Introduces Autodata: An Agentic Framework That Turns AI Models into Autonomous Data Scientists for High-Quality Training Data Creation A Coding Guide on LLM Post Training with TRL from Supervised Fine Tuning to DPO and GRPO Reasoning Qwen AI Releases Qwen-Scope: An Open-Source Sparse AutoEncoders (SAE) Suite That Turns LLM Internal Features into Practical Development Tools A Coding Deep Dive into Agentic UI, Generative UI, State Synchronization, and Interrupt-Driven Approval Flows Moonshot AI Open-Sources FlashKDA: CUTLASS Kernels for Kimi Delta Attention with Variable-Length Batching and H20 Benchmarks Microsoft Research’s World-R1 Uses Flow-GRPO and 3D-Aware Rewards to Inject Geometric Consistency Into Wan 2.1 Without Architectural Changes A Coding Implementation on Pyright Type Checking Covering Generics, Protocols, Strict Mode, Type Narrowing, and Modern Python Typing IBM Releases Two Granite Speech 4.1 2B Models: Autoregressive ASR with Translation and Non-Autoregressive Editing for Fast Inference Top 10 KV Cache Compression Techniques for LLM Inference: Reducing Memory Overhead Across Eviction, Quantization, and Low-Rank Methods Qwen Team Releases FlashQLA: a High-Performance Linear Attention Kernel Library That Achieves Up to 3× Speedup on NVIDIA Hopper GPUs Step by Step Guide to Build a Complete PII Detection and Redaction Pipeline with OpenAI Privacy Filter Meta FAIR Releases NeuralSet: A Python Package for Neuro-AI That Supports fMRI, M/EEG, Spikes, and HuggingFace Embeddings smol-audio: A Colab-Friendly Notebook Collection for Fine-Tuning Whisper, Parakeet, Voxtral, Granite Speech, and Audio Flamingo 3 A Coding Implementation on Document Parsing Benchmarking with LlamaIndex ParseBench Using Python, Hugging Face, and Evaluation Metrics Poolside AI Introduces Laguna XS.2 and M.1: Agentic Coding Models Reaching 68.2% and 72.5% on SWE-bench Verified How to Build Traceable and Evaluated LLM Workflows Using Promptflow, Prompty, and OpenAI OpenAI Releases Privacy Filter: A 1.5B-Parameter Open-Source PII Redaction Model with 50M Active Parameters Top 10 Physical AI Models Powering Real-World Robots in 2026 How to Build a Lightweight Vision-Language-Action-Inspired Embodied Agent with Latent World Modeling and Model Predictive Control Meet Talkie-1930: A 13B Open-Weight LLM Trained on Pre-1931 English Text for Historical Reasoning and Generalization Research Build a Reinforcement Learning Powered Agent that Learns to Retrieve Relevant Long-Term Memories for Accurate LLM Question Answering OpenMOSS Releases MOSS-Audio: An Open-Source Foundation Model for Speech, Sound, Music, and Time-Aware Audio Reasoning Meta AI Releases Sapiens2: A High-Resolution Human-Centric Vision Model for Pose, Segmentation, Normals, Pointmap, and Albedo The LoRA Assumption That Breaks in Production How to Build a Fully Searchable AI Knowledge Base with OpenKB, OpenRouter, and Llama How to Build Smarter Multilingual Text Wrapping with BudouX Through Parsing, HTML Rendering, Model Introspection, and Toy Training Top 7 Benchmarks That Actually Matter for Agentic Reasoning in Large Language Models RAG Without Vectors: How PageIndex Retrieves by Reasoning xAI Launches grok-voice-think-fast-1.0: Topping τ-voice Bench at 67.3%, Outperforming Gemini, GPT Realtime, and More A Coding Implementation on kvcached for Elastic KV Cache Memory, Bursty LLM Serving, and Multi-Model GPU Sharing Google DeepMind Introduces Vision Banana: An Instruction-Tuned Image Generator That Beats SAM 3 on Segmentation and Depth Anything V3 on Metric Depth Estimation Meet GitNexus: An Open-Source MCP-Native Knowledge Graph Engine That Gives Claude Code and Cursor Full Codebase Structural Awareness A Coding Implementation on Deepgram Python SDK for Transcription, Text-to-Speech, Async Audio Processing, and Text Intelligence A Coding Implementation on Microsoft’s OpenMementos with Trace Structure Analysis, Context Compression, and Fine-Tuning Data Preparation DeepSeek AI Releases DeepSeek-V4: Compressed Sparse Attention and Heavily Compressed Attention Enable One-Million-Token Contexts Google DeepMind Introduces Decoupled DiLoCo: An Asynchronous Training Architecture Achieving 88% Goodput Under High Hardware Failure Rates Mend Releases AI Security Governance Framework: Covering Asset Inventory, Risk Tiering, AI Supply Chain Security, and Maturity Model Mend.io Releases AI Security Governance Framework Covering Asset Inventory, Risk Tiering, AI Supply Chain Security, and Maturity Model OpenAI Releases GPT-5.5, a Fully Retrained Agentic Model That Scores 82.7% on Terminal-Bench 2.0 and 84.9% on GDPval A Coding Tutorial on OpenMythos on Recurrent-Depth Transformers with Depth Extrapolation, Adaptive Computation, and Mixture-of-Experts Routing Google Cloud AI Research Introduces ReasoningBank: A Memory Framework that Distills Reasoning Strategies from Agent Successes and Failures Xiaomi Releases MiMo-V2.5-Pro and MiMo-V2.5: Matching Frontier Model Benchmarks at Significantly Lower Token Cost How to Design a Production-Grade CAMEL Multi-Agent System with Planning, Tool Use, Self-Consistency, and Critique-Driven Refinement Alibaba Qwen Team Releases Qwen3.6-27B: A Dense Open-Weight Model Outperforming 397B MoE on Agentic Coding Benchmarks A Detailed Implementation on Equinox with JAX Native Modules, Filtered Transforms, Stateful Layers, and End-to-End Training Workflows Next Leap to Harness Engineering: JiuwenClaw Pioneers ‘Coordination Engineering’ Photon Releases Spectrum: An Open-Source TypeScript Framework that Deploys AI Agents Directly to iMessage, WhatsApp, and Telegram OpenAI Open-Sources Euphony: A Browser-Based Visualization Tool for Harmony Chat Data and Codex Session Logs Hugging Face Releases ml-intern: An Open-Source AI Agent that Automates the LLM Post-Training Workflow A Coding Implementation to Build a Conditional Bayesian Hyperparameter Optimization Pipeline with Hyperopt, TPE, and Early Stopping Google Introduces Simula: A Reasoning-First Framework for Generating Controllable, Scalable Synthetic Datasets Across Specialized AI Domains A Coding Implementation on Qwen 3.6-35B-A3B Covering Multimodal Inference, Thinking Control, Tool Calling, MoE Routing, RAG, and Session Persistence Moonshot AI Releases Kimi K2.6 with Long-Horizon Coding, Agent Swarm Scaling to 300 Sub-Agents and 4,000 Coordinated Steps A Coding Implementation on Microsoft’s Phi-4-Mini for Quantized Inference Reasoning Tool Use RAG and LoRA Fine-Tuning OpenAI Scales Trusted Access for Cyber Defense With GPT-5.4-Cyber: a Fine-Tuned Model Built for Verified Security Defenders Moonshot AI and Tsinghua Researchers Propose PrfaaS: A Cross-Datacenter KVCache Architecture that Rethinks How LLMs are Served at Scale Meet OpenMythos: An Open-Source PyTorch Reconstruction of Claude Mythos Where 770M Parameters Match a 1.3B Transformer How TabPFN Leverages In-Context Learning to Achieve Superior Accuracy on Tabular Datasets Compared to Random Forest and CatBoost A Coding Implementation to Build an AI-Powered File Type Detection and Security Analysis Pipeline with Magika and OpenAI NVIDIA Releases Ising: the First Open Quantum AI Model Family for Hybrid Quantum-Classical Systems xAI Launches Standalone Grok Speech-to-Text and Text-to-Speech APIs, Targeting Enterprise Voice Developers A Coding Tutorial for Running PrismML Bonsai 1-Bit LLM on CUDA with GGUF, Benchmarking, Chat, JSON, and RAG A Coding Guide for Property-Based Testing Using Hypothesis with Stateful, Differential, and Metamorphic Test Design Anthropic Releases Claude Opus 4.7: A Major Upgrade for Agentic Coding, High-Resolution Vision, and Long-Horizon Autonomous Tasks Google AI Releases Auto-Diagnose: An Large Language Model LLM-Based System to Diagnose Integration Test Failures at Scale A End-to-End Coding Guide to Running OpenAI GPT-OSS Open-Weight Models with Advanced Inference Workflows Top 19 AI Red Teaming Tools (2026): Secure Your ML Models A Coding Guide to Build a Production-Grade Background Task Processing System Using Huey with SQLite, Scheduling, Retries, Pipelines, and Concurrency Control Qwen Team Open-Sources Qwen3.6-35B-A3B: A Sparse MoE Vision-Language Model with 3B Active Parameters and Agentic Coding Capabilities OpenAI Launches GPT-Rosalind: Its First Life Sciences AI Model Built to Accelerate Drug Discovery and Genomics Research Building Transformer-Based NQS for Frustrated Spin Systems with NetKet UCSD and Together AI Research Introduces Parcae: A Stable Architecture for Looped Language Models That Achieves the Quality of a Transformer Twice the Size How to Build a Universal Long-Term Memory Layer for AI Agents Using Mem0 and OpenAI A Coding Implementation to Build Multi-Agent AI Systems with SmolAgents Using Code Execution, Tool Calling, and Dynamic Orchestration A Technical Deep Dive into the Essential Stages of Modern Large Language Model Training, Alignment, and Deployment Google AI Launches Gemini 3.1 Flash TTS: A New Benchmark in Expressive and Controllable AI Voice Google DeepMind Releases Gemini Robotics-ER 1.6: Bringing Enhanced Embodied Reasoning and Instrument Reading to Physical AI Google Launches ‘Skills’ in Chrome: Turning Reusable AI Prompts into One-Click Browser Workflows A Coding Implementation of Crawl4AI for Web Crawling, Markdown Generation, JavaScript Execution, and LLM-Based Structured Extraction TinyFish AI Releases Full Web Infrastructure Platform for AI Agents: Search, Fetch, Browser, and Agent Under One API Key NVIDIA and the University of Maryland Researchers Released Audio Flamingo Next (AF-Next): A Super Powerful and Open Large Audio-Language Model A Hands-On Coding Tutorial for Microsoft VibeVoice Covering Speaker-Aware ASR, Real-Time TTS, and Speech-to-Speech Pipelines Meta AI and KAUST Researchers Propose Neural Computers That Fold Computation, Memory, and I/O Into One Learned Model A Coding Implementation of MolmoAct for Depth-Aware Spatial Reasoning, Visual Trajectory Tracing, and Robotic Action Prediction MiniMax Just Open Sourced MiniMax M2.7: A Self-Evolving Agent Model that Scores 56.22% on SWE-Pro and 57.0% on Terminal Bench 2 Liquid AI Releases LFM2.5-VL-450M: a 450M-Parameter Vision-Language Model with Bounding Box Prediction, Multilingual Support, and Sub-250ms Edge Inference Researchers from MIT, NVIDIA, and Zhejiang University Propose TriAttention: A KV Cache Compression Method That Matches Full Attention at 2.5× Higher Throughput How to Build a Secure Local-First Agent Runtime with OpenClaw Gateway, Skills, and Controlled Tool Execution How Knowledge Distillation Compresses Ensemble Intelligence into a Single Deployable AI Model Alibaba’s Tongyi Lab Releases VimRAG: a Multimodal RAG Framework that Uses a Memory Graph to Navigate Massive Visual Contexts A Coding Guide to Markerless 3D Human Kinematics with Pose2Sim, RTMPose, and OpenSim NVIDIA Releases AITune: An Open-Source Inference Toolkit That Automatically Finds the Fastest Inference Backend for Any PyTorch Model Five AI Compute Architectures Every Engineer Should Know: CPUs, GPUs, TPUs, NPUs, and LPUs Compared An End-to-End Coding Guide to NVIDIA KVPress for Long-Context LLM Inference, KV Cache Compression, and Memory-Efficient Generation Meta Superintelligence Lab Releases Muse Spark: A Multimodal Reasoning Model With Thought Compression and Parallel Agents Sigmoid vs ReLU Activation Functions: The Inference Cost of Losing Geometric Context A Coding Guide to Build Advanced Document Intelligence Pipelines with Google LangExtract, OpenAI Models, Structured Extraction, and Interactive Visualization Google AI Research Introduces PaperOrchestra: A Multi-Agent Framework for Automated AI Research Paper Writing A Comprehensive Implementation Guide to ModelScope for Model Search, Inference, Fine-Tuning, Evaluation, and Export
A Coding Tutorial on Datashader on Rendering Massive Datasets with High-Performance Python Visual Analytics
Sana Hassan · 2026-04-26 · via MarkTechPost

In this tutorial, we explore Datashader, a powerful, high-performance visualization library for rendering massive datasets that quickly overwhelm traditional plotting tools. We work through its full rendering pipeline in Google Colab, starting from dense point clouds and reduction-based aggregations to categorical rendering, line visualizations, raster data, quadmesh grids, compositing, and dashboard-style analytical views. As we move through each section, we focus on how Datashader transforms raw large-scale data into meaningful visual structure with speed, flexibility, and visual clarity, while keeping Matplotlib as the final presentation layer.

import subprocess, sys
subprocess.check_call([sys.executable, "-m", "pip", "install", "-q",
                      "datashader", "colorcet", "numba", "scipy"])


import numpy  as np
import pandas as pd
import datashader as ds
import datashader.transfer_functions as tf
from datashader import reductions as rd
import colorcet as cc
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.gridspec import GridSpec
from scipy.stats import multivariate_normal
import time, warnings
warnings.filterwarnings("ignore")


print("Datashader version:", ds.__version__)


def show(img, title="", ax=None, figsize=(6, 5)):
   standalone = ax is None
   if standalone:
       fig, ax = plt.subplots(figsize=figsize)
   rgba = img.to_pil()
   ax.imshow(rgba, origin="upper", aspect="auto")
   ax.set_title(title, fontsize=11, fontweight="bold")
   ax.axis("off")
   if standalone:
       plt.tight_layout()
       plt.show()


print("\n=== SECTION 1: Core Pipeline ===")


rng = np.random.default_rng(42)
N   = 2_000_000


x = np.concatenate([rng.normal(-1, 0.5, N//3),
                   rng.normal( 1, 0.5, N//3),
                   rng.normal( 0, 1.5, N//3)])
y = np.concatenate([rng.normal(-1, 0.5, N//3),
                   rng.normal( 1, 0.5, N//3),
                   rng.normal( 0, 0.5, N//3)])
df_base = pd.DataFrame({"x": x, "y": y})


canvas = ds.Canvas(plot_width=600, plot_height=500,
                  x_range=(-4, 4), y_range=(-4, 4))


agg = canvas.points(df_base, "x", "y", agg=rd.count())


fig, axes = plt.subplots(1, 3, figsize=(15, 4))
combos = [
   ("Linear / blues",  tf.shade(agg, cmap=cc.blues,        how="linear")),
   ("Log    / fire",   tf.shade(agg, cmap=cc.fire,         how="log"   )),
   ("Eq-hist / bmy",   tf.shade(agg, cmap=cc.bmy,          how="eq_hist")),
]
for ax, (title, img) in zip(axes, combos):
   show(img, title, ax=ax)
plt.suptitle("Section 1 – 2 M points: Linear vs Log vs Eq-Hist normalisation",
            fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()


print("\n=== SECTION 2: Reduction Types ===")


n_actual = len(df_base)
df_base["value"] = rng.exponential(scale=2, size=n_actual)
df_base["label"] = pd.Categorical(
   rng.choice(["A", "B", "C"], size=n_actual),
   categories=["A", "B", "C"]
)


canvas2 = ds.Canvas(plot_width=400, plot_height=350,
                   x_range=(-4, 4), y_range=(-4, 4))


reductions_cfg = [
   ("count()",          rd.count(),                 cc.kbc),
   ("sum(value)",       rd.sum("value"),             cc.CET_L3),
   ("mean(value)",      rd.mean("value"),            cc.CET_D4),
   ("std(value)",       rd.std("value"),             cc.CET_L16),
   ("min(value)",       rd.min("value"),             cc.CET_L17),
   ("max(value)",       rd.max("value"),             cc.bgyw),
   ("var(value)",       rd.var("value"),             cc.CET_L18),
   ("count_cat(label)", rd.count_cat("label"),       None),
]


fig, axes = plt.subplots(2, 4, figsize=(18, 9))
axes = axes.flat


for ax, (name, agg_fn, cmap) in zip(axes, reductions_cfg):
   agg_r = canvas2.points(df_base, "x", "y", agg=agg_fn)
   if cmap is None:
       img = tf.shade(agg_r, color_key={"A":"#e41a1c","B":"#377eb8","C":"#4daf4a"})
   else:
       img = tf.shade(agg_r, cmap=cmap, how="eq_hist")
   show(img, name, ax=ax)


plt.suptitle("Section 2 – All Reduction Types on 2 M points", fontsize=14, fontweight="bold")
plt.tight_layout()
plt.show()


print("\n=== SECTION 3: Categorical Visualisation ===")


N_cat = 500_000
categories = ["Cluster A", "Cluster B", "Cluster C", "Cluster D"]
centers = [(-2, -2), (-2, 2), (2, -2), (2, 2)]
colors  = {"Cluster A":"#e41a1c","Cluster B":"#377eb8",
          "Cluster C":"#4daf4a","Cluster D":"#ff7f00"}


frames = []
for cat, (cx, cy) in zip(categories, centers):
   n = N_cat // len(categories)
   frames.append(pd.DataFrame({
       "x":    rng.normal(cx, 0.8, n),
       "y":    rng.normal(cy, 0.8, n),
       "cat":  pd.Categorical([cat]*n, categories=categories),
   }))
df_cat = pd.concat(frames, ignore_index=True)


canvas3 = ds.Canvas(plot_width=500, plot_height=500,
                   x_range=(-5, 5), y_range=(-5, 5))
agg_cat = canvas3.points(df_cat, "x", "y", agg=rd.count_cat("cat"))


fig, axes = plt.subplots(1, 3, figsize=(16, 5))


img_raw  = tf.shade(agg_cat, color_key=colors)
show(img_raw, "Raw (no spread)", ax=axes[0])


img_sp1  = tf.spread(tf.shade(agg_cat, color_key=colors), px=1)
show(img_sp1, "Spread px=1", ax=axes[1])


img_bg   = tf.set_background(tf.shade(agg_cat, color_key=colors), color="black")
show(img_bg, "Black background", ax=axes[2])


for cat, col in colors.items():
   axes[2].plot([], [], "o", color=col, label=cat, markersize=8)
axes[2].legend(loc="lower right", fontsize=8, framealpha=0.6)


plt.suptitle("Section 3 – Categorical Rendering (500 k points)", fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()

We install the required libraries and import everything needed to build a complete Datashader workflow in Google Colab. We define a helper function to display Datashader images with Matplotlib, which keeps the rendering pipeline simple and visually consistent. We then begin with the core Datashader pipeline, explore multiple reduction types, and show how categorical data can be rendered clearly using color keys, spreading, and background adjustments.

print("\n=== SECTION 4: Line Rendering ===")


n_series, n_steps = 5_000, 500
t  = np.linspace(0, 1, n_steps)
xs = np.tile(t, n_series)


walks = np.cumsum(rng.normal(0, 0.05, (n_series, n_steps)), axis=1)
ys    = walks.ravel()


series_id = np.repeat(np.arange(n_series), n_steps)
df_lines  = pd.DataFrame({"x": xs, "y": ys, "id": series_id})


canvas4 = ds.Canvas(plot_width=700, plot_height=450,
                   x_range=(0, 1), y_range=(-6, 6))


agg_lines = canvas4.line(df_lines, "x", "y",
                        agg=rd.count(), line_width=1)


fig, axes = plt.subplots(1, 2, figsize=(14, 5))
show(tf.shade(agg_lines, cmap=cc.fire,  how="eq_hist"),
    "5 000 random walks – eq_hist / fire", ax=axes[0])
show(tf.shade(agg_lines, cmap=cc.blues, how="log"),
    "5 000 random walks – log / blues",    ax=axes[1])
plt.suptitle("Section 4 – Line / Time-Series Rendering", fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()


print("\n=== SECTION 5: Raster / Grid Data ===")


import xarray as xr


res = 1000
lon = np.linspace(-180, 180, res)
lat = np.linspace(-90,   90, res)
LON, LAT = np.meshgrid(lon, lat)


z = (  multivariate_normal.pdf(np.stack([LON, LAT], -1),
                               mean=[30, 30], cov=[[800,0],[0,500]])
    + multivariate_normal.pdf(np.stack([LON, LAT], -1),
                               mean=[-60, -20], cov=[[600,0],[0,400]])
    + 0.02 * rng.standard_normal((res, res)))


da = xr.DataArray(z, dims=["y", "x"],
                 coords={"x": lon, "y": lat})


canvas5 = ds.Canvas(plot_width=700, plot_height=400,
                   x_range=(-180, 180), y_range=(-90, 90))
agg_raster = canvas5.raster(da)


fig, axes = plt.subplots(1, 2, figsize=(14, 4))
show(tf.shade(agg_raster, cmap=cc.CET_L18, how="eq_hist"),
    "Synthetic elevation – eq_hist", ax=axes[0])
show(tf.shade(agg_raster, cmap=cc.rainbow,  how="linear"),
    "Synthetic elevation – linear",  ax=axes[1])
plt.suptitle("Section 5 – Raster / Grid (xarray DataArray)", fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()


print("\n=== SECTION 6: QuadMesh / 2-D Grid Glyph ===")


lon6  = np.concatenate([np.linspace(-180, -60, 80),
                        np.linspace(-60,   60, 30),
                        np.linspace( 60,  180, 80)])
lat6  = np.concatenate([np.linspace(-90, -30, 40),
                        np.linspace(-30,  30, 20),
                        np.linspace( 30,  90, 40)])
LON6, LAT6 = np.meshgrid(lon6, lat6)


def vortex(lon0, lat0, amp=1.0):
   return amp * np.exp(-((LON6-lon0)**2/1200 + (LAT6-lat0)**2/600))


field6 = vortex(-40, 30, 1.2) + vortex(120, -20, 0.9) + \
        0.05 * rng.standard_normal(LON6.shape)


da6 = xr.DataArray(field6.astype(np.float32),
                  dims=["y", "x"],
                  coords={"x": lon6, "y": lat6},
                  name="intensity")


canvas6 = ds.Canvas(plot_width=700, plot_height=380,
                   x_range=(-180, 180), y_range=(-90, 90))
agg6    = canvas6.quadmesh(da6)


canvas6z = ds.Canvas(plot_width=500, plot_height=400,
                    x_range=(-80, 0), y_range=(0, 60))
agg6z    = canvas6z.quadmesh(da6)


field6_smooth = vortex(-40, 30, 1.0) + vortex(120, -20, 0.8)
da6_diff = xr.DataArray((field6 - field6_smooth).astype(np.float32),
                        dims=["y","x"],
                        coords={"x": lon6, "y": lat6},
                        name="anomaly")
agg6d = canvas6.quadmesh(da6_diff)


fig, axes = plt.subplots(1, 3, figsize=(18, 5))
show(tf.shade(agg6,  cmap=cc.fire,   how="eq_hist"), "Global field – eq_hist",      ax=axes[0])
show(tf.shade(agg6z, cmap=cc.CET_L3, how="linear"),  "N. Atlantic zoom – linear",   ax=axes[1])
show(tf.shade(agg6d, cmap=cc.CET_D4, how="eq_hist"), "Residual (anomaly) – eq_hist",ax=axes[2])
plt.suptitle("Section 6 – canvas.quadmesh(): non-uniform 2-D grids",
            fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()

We move beyond point clouds and use Datashader to render thousands of overlapping random-walk lines efficiently without visual clutter. We then work with raster and grid-based data through xarray, showing how Datashader handles continuous spatial fields and non-uniform quadmesh structures with ease. By the end of this part, we explore global fields, local zoom views, and anomaly-style visual comparisons to understand Datashader’s strength on structured 2-D data.

print("\n=== SECTION 7: Spreading, Stack & Composite ===")


N7 = 300_000
x7 = rng.normal(0, 3, N7)
y7 = rng.normal(0, 3, N7)
df7 = pd.DataFrame({"x": x7, "y": y7})


canvas7 = ds.Canvas(plot_width=500, plot_height=500,
                   x_range=(-10, 10), y_range=(-10, 10))
agg7 = canvas7.points(df7, "x", "y", agg=rd.count())


fig, axes = plt.subplots(1, 4, figsize=(20, 5))
for ax, (label, px) in zip(axes, [("No spread", 0), ("spread px=1", 1),
                                  ("spread px=2", 2), ("spread px=4", 4)]):
   img = tf.shade(agg7, cmap=cc.fire, how="eq_hist")
   if px > 0:
       img = tf.spread(img, px=px)
   show(img, label, ax=ax)


plt.suptitle("Section 7 – Effect of spread() on sparse data", fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()


N_fg = 50_000
x_fg = rng.normal(0, 0.5, N_fg)
y_fg = rng.normal(0, 0.5, N_fg)
df_fg = pd.DataFrame({"x": x_fg, "y": y_fg})


agg_bg = canvas7.points(df7,  "x", "y", agg=rd.count())
agg_fg = canvas7.points(df_fg,"x", "y", agg=rd.count())


img_bg_shade = tf.shade(agg_bg, cmap=cc.blues, how="log",   alpha=200)
img_fg_shade = tf.shade(agg_fg, cmap=cc.fire,  how="eq_hist")


stacked = tf.stack(img_bg_shade, img_fg_shade)


fig, axes = plt.subplots(1, 3, figsize=(15, 5))
show(img_bg_shade, "Background (blue / log)",    ax=axes[0])
show(img_fg_shade, "Foreground (fire / eq_hist)", ax=axes[1])
show(stacked,      "Stacked composite",           ax=axes[2])
plt.suptitle("Section 7 – Stack / Composite two layers", fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()


print("\n=== SECTION 8: Performance Benchmark ===")


sizes    = [10_000, 100_000, 1_000_000, 5_000_000, 20_000_000]
timings  = []


for n in sizes:
   xb = rng.normal(0, 1, n).astype(np.float32)
   yb = rng.normal(0, 1, n).astype(np.float32)
   dfb = pd.DataFrame({"x": xb, "y": yb})
   cvb = ds.Canvas(plot_width=800, plot_height=700)
   cvb.points(dfb, "x", "y", agg=rd.count())
   t0  = time.perf_counter()
   cvb.points(dfb, "x", "y", agg=rd.count())
   elapsed = time.perf_counter() - t0
   timings.append(elapsed)
   print(f"  {n:>12,} points → {elapsed*1000:6.1f} ms")


fig, ax = plt.subplots(figsize=(8, 4))
ax.loglog([s/1e6 for s in sizes], [t*1000 for t in timings],
         "o-", linewidth=2, markersize=8, color="#e41a1c")
ax.set_xlabel("Dataset size (millions of points)", fontsize=12)
ax.set_ylabel("Render time (ms)",                  fontsize=12)
ax.set_title("Section 8 – Datashader Render Performance (800×700 canvas)",
            fontsize=12, fontweight="bold")
ax.grid(True, which="both", alpha=0.4)
plt.tight_layout()
plt.show()


print("\n=== SECTION 9: Custom Matplotlib Colourmap Pipeline ===")


N9 = 3_000_000
angle   = rng.uniform(0, 2*np.pi, N9)
radius  = rng.exponential(1.5, N9)
x9 = radius * np.cos(angle)
y9 = radius * np.sin(angle)
df9 = pd.DataFrame({"x": x9.astype(np.float32),
                   "y": y9.astype(np.float32)})


canvas9 = ds.Canvas(plot_width=600, plot_height=600,
                   x_range=(-8, 8), y_range=(-8, 8))
agg9 = canvas9.points(df9, "x", "y", agg=rd.count())


mpl_cmaps = ["inferno", "plasma", "viridis", "cividis"]
fig, axes = plt.subplots(1, 4, figsize=(18, 5))
for ax, cmap_name in zip(axes, mpl_cmaps):
   cmap = plt.get_cmap(cmap_name)
   colours = [mcolors.to_hex(cmap(i/255)) for i in range(256)]
   img = tf.shade(agg9, cmap=colours, how="eq_hist")
   show(img, f"mpl: {cmap_name}", ax=ax)


plt.suptitle("Section 9 – Any Matplotlib colourmap with Datashader",
            fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()

We focus on spreading, stacking, and compositing to see how Datashader improves the visibility of sparse data and combines multiple rendered layers into a single visual output. We then benchmark performance across datasets ranging from thousands to tens of millions of points, which helps us observe how rendering time scales with data size. Finally, we build a custom color pipeline using Matplotlib colormaps, showing how we can connect Datashader’s aggregation engine with familiar visualization palettes.

print("\n=== SECTION 10: Multi-Panel Dashboard ===")


N10   = 1_500_000
price = np.cumsum(rng.normal(0, 0.01, N10)) + 100
vol   = np.abs(rng.normal(0, 1, N10)) * (1 + 0.5 * rng.exponential(1, N10))
ret   = np.diff(price, prepend=price[0])
hour  = (np.arange(N10) % 390) / 390


df10 = pd.DataFrame({
   "price": price.astype(np.float32),
   "vol":   vol.astype(np.float32),
   "ret":   ret.astype(np.float32),
   "hour":  hour.astype(np.float32),
})


fig = plt.figure(figsize=(16, 12))
gs  = GridSpec(2, 3, figure=fig, hspace=0.35, wspace=0.3)


panels = [
   (gs[0,0], "price", "vol",  "Price vs Volume",          cc.fire),
   (gs[0,1], "ret",   "vol",  "Return vs Volume",         cc.bmy),
   (gs[0,2], "hour",  "price","Intraday Price Distribution",cc.CET_L3),
   (gs[1,0], "ret",   "price","Return vs Price",           cc.CET_D4),
   (gs[1,1], "hour",  "ret",  "Intraday Return Profile",  cc.CET_L16),
   (gs[1,2], "hour",  "vol",  "Intraday Volume Profile",  cc.CET_L17),
]


for spec, xcol, ycol, title, cmap in panels:
   ax  = fig.add_subplot(spec)
   xr_ = (float(df10[xcol].quantile(0.001)),
          float(df10[xcol].quantile(0.999)))
   yr_ = (float(df10[ycol].quantile(0.001)),
          float(df10[ycol].quantile(0.999)))
   cv  = ds.Canvas(plot_width=300, plot_height=250,
                   x_range=xr_, y_range=yr_)
   ag  = cv.points(df10, xcol, ycol, agg=rd.count())
   img = tf.shade(ag, cmap=cmap, how="eq_hist")
   show(img, title, ax=ax)
   ax.set_axis_off()


fig.suptitle("Section 10 – Multi-Panel Dashboard: 1.5 M Synthetic Trades",
            fontsize=15, fontweight="bold", y=1.01)
plt.show()


print("\n=== SECTION 11: Zoom / Sub-Region Magnification ===")


zoom_ranges = [
   ((-5, 5),    (-5, 5),    "Full extent"),
   ((-3, 0),    (-3, 0),    "Quadrant III"),
   ((-1.5, 0.5),(-1.5, 0.5),"Zoomed into cluster A"),
]


fig, axes = plt.subplots(1, 3, figsize=(15, 5))
for ax, (xr, yr, title) in zip(axes, zoom_ranges):
   cv = ds.Canvas(plot_width=400, plot_height=400, x_range=xr, y_range=yr)
   ag = cv.points(df_cat, "x", "y", agg=rd.count_cat("cat"))
   img = tf.shade(ag, color_key=colors)
   show(img, title, ax=ax)


plt.suptitle("Section 11 – Zoom: No Data Loss at Any Scale", fontsize=13, fontweight="bold")
plt.tight_layout()
plt.show()

We create a multi-panel dashboard that uses Datashader repeatedly across several variable pairs, allowing us to inspect large synthetic trading-style data from multiple analytical perspectives at once. We calculate robust plotting ranges using quantiles, ensuring each panel focuses on the most informative region of the data. We then demonstrate zoom-based magnification, showing that Datashader preserves detail at every scale and allows us to inspect subregions without losing data fidelity.

print("\n=== SECTION 12: Overlay with Matplotlib ===")


canvas12 = ds.Canvas(plot_width=600, plot_height=600,
                    x_range=(-4, 4), y_range=(-4, 4))
agg12 = canvas12.points(df_base, "x", "y", agg=rd.count())
img12 = tf.shade(agg12, cmap=cc.fire, how="eq_hist")


from scipy.stats import gaussian_kde
sample_idx = rng.integers(0, len(df_base), 20_000)
kde   = gaussian_kde(df_base.iloc[sample_idx][["x","y"]].values.T, bw_method=0.15)
gx    = np.linspace(-4, 4, 80)
gy    = np.linspace(-4, 4, 80)
GX, GY = np.meshgrid(gx, gy)
Z     = kde(np.vstack([GX.ravel(), GY.ravel()])).reshape(GX.shape)


fig, ax = plt.subplots(figsize=(7, 6))
ax.imshow(img12.to_pil(), origin="upper", aspect="auto",
         extent=[-4, 4, -4, 4])
ax.contour(GX, GY, Z, levels=8, colors="white", linewidths=0.8, alpha=0.7)
ax.set_title("Section 12 – Datashader + Matplotlib Contour Overlay",
            fontsize=12, fontweight="bold")
ax.set_xlabel("x"); ax.set_ylabel("y")
plt.tight_layout()
plt.show()


print("\n✅  All sections complete!")

We combine Datashader with Matplotlib overlays by rendering a dense, aggregated image and then placing contour lines on top using a KDE computed from a sampled subset of points. This shows how Datashader can serve as the high-performance visual foundation, while Matplotlib adds additional analytical annotations. We finish the tutorial by completing the full workflow and demonstrating how large-scale rendering and traditional plotting can work together effectively.

In conclusion, we built a strong practical understanding of how Datashader efficiently and scalably handles millions of points, multiple glyph types, grid-based data, layered composites, and custom color workflows. We saw how its aggregation-first approach enables preservation of detail, avoidance of overplotting, and zooming into dense regions without losing fidelity. Through these examples, we learn how to use Datashader’s key features in practice and understand why it is such a valuable tool for advanced large-scale data visualization workflows in Python.


Check out the Full Codes here. Find 100s of ML/Data Science Colab Notebooks here. Also, feel free to follow us on Twitter and don’t forget to join our 130k+ ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.

Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? Connect with us

Sana Hassan, a consulting intern at Marktechpost and dual-degree student at IIT Madras, is passionate about applying technology and AI to address real-world challenges. With a keen interest in solving practical problems, he brings a fresh perspective to the intersection of AI and real-life solutions.