Skip to content

Scatter

Points of a sunflower spiral drawn as filled markers, each coloured by the value of the Julia field at its position and sized by its distance from the centre.

Scatter

The figure above is live, drawn in the browser by the same engine that draws the viewer: drag it to pan, and click it to zoom with the wheel. Download the PDF for the vector figure that IronLAB exports, or read how to embed a figure of your own.

Source

The figure is built by the following code. Its data comes from the functions on the data helpers page.

use ironlab::prelude::*;

use crate::fields::*;

pub const TITLE: &str = "Scatter";
pub const DESCRIPTION: &str = "Points of a sunflower spiral drawn as filled markers, each coloured by the value of \
     the Julia field at its position and sized by its distance from the centre.";

pub fn figure() -> Figure {
    let (x, y) = sunflower(400, 1.5);
    let field_value: Vec<f64> = x.iter().zip(&y).map(|(&x, &y)| julia_field(x, y)).collect();
    // Markers grow from 2 pt at the centre to 5 pt at the rim.
    let marker_size: Vec<f64> = x.iter().zip(&y).map(|(&x, &y)| 2.0 + 2.0 * x.hypot(y)).collect();

    let mut fig = Figure::new()
        .size_mm(120.0, 100.0)
        .title("Julia field sampled on a sunflower spiral")
        .label("scatter")
        .label("basics")
        .label("colormap")
        .label("markers")
        .parameter("dimensionality", "2D")
        .parameter("artists", 1)
        .parameter("data_points", 1600)
        .parameter("has_legend", false);
    let mut ax = fig.axes(0, 0);
    ax.scatter(&x, &y)
        .colors(&field_value)
        .sizes(&marker_size)
        .marker(Marker::Circle)
        .filled();
    ax.colormap(Colormap::Plasma)
        .xlabel("$x$")
        .ylabel("$y$")
        .xlim(-1.6, 1.6)
        .ylim(-1.6, 1.6);
    fig
}

Back to the gallery