A step-by-step guide to building 2D histograms in pure Ruby using the ruby-libgd gem, replicating a classic matplotlib example. Covers implementing the Box-Muller transform for normal random data generation, binning a 2D grid, applying gamma-corrected color mapping, and extending the approach to real CSV data. The Hist2D class is designed as a pure renderer that accepts data arrays, making it compatible with synthetic data, CSV files, or database queries. The workflow is demonstrated in Jupyter notebooks.

5m read timeFrom rubystacknews.com
Post cover image
Table of contents
What is a 2D histogram?The matplotlib originalDesign decision — the class receives data, it does not generate itBuilding it in RubyStep 1 — Normal random dataStep 2 — Bin the dataStep 3 — Color and drawResult — synthetic dataGoing further — real CSV dataThe full workflow in JupyterWhat comes nextShare this:Related

Sort: