Thread overview
How to plot a simple scatter plot using ggplotd
3 days ago
Marc
2 days ago
Serg Gini
2 days ago
Marc
3 days ago

Hello everyone,
I am trying to use ggplotd to visualize a data set before and after fitting a linear model. how ever i'm struggling to get it to work with a simple example. I tried the following and i get errors for boths:

import mir.ndslice;
import ggplotd.aes: aes, Aes;
import ggplotd.axes: xaxisLabel, yaxisLabel;
import ggplotd.ggplotd: GGPlotD, putIn;
import ggplotd.geom: geomPoint, geomBox, geomLine;

void main(){
   auto x = [1.47f, 1.50f, 1.52f].sliced(3);
   auto y = [52.21f, 53.12f, 54.48f].sliced(3);
   auto xs = x.array;
   auto ys = y.array;
   auto gg = aes!("x", "y")(xs, ys).geomPoint;
   // or
   auto gs = aes!("x", "y")(xs, ys).array.geomPoint;
}

I would appreciate any help or advice on getting it to work.

2 days ago

On Tuesday, 12 August 2025 at 02:23:49 UTC, Marc wrote:

>

Hello everyone,
I am trying to use ggplotd to visualize a data set before and after fitting a linear model. how ever i'm struggling to get it to work with a simple example. I tried the following and i get errors for boths:

import mir.ndslice;
import ggplotd.aes: aes, Aes;
import ggplotd.axes: xaxisLabel, yaxisLabel;
import ggplotd.ggplotd: GGPlotD, putIn;
import ggplotd.geom: geomPoint, geomBox, geomLine;

void main(){
   auto x = [1.47f, 1.50f, 1.52f].sliced(3);
   auto y = [52.21f, 53.12f, 54.48f].sliced(3);
   auto xs = x.array;
   auto ys = y.array;
   auto gg = aes!("x", "y")(xs, ys).geomPoint;
   // or
   auto gs = aes!("x", "y")(xs, ys).array.geomPoint;
}

I would appreciate any help or advice on getting it to work.

auto gg = xs.zip(ys)
            .map!((t) => aes!("x","y")(t[0], t[1]))
            .geomPoint.putIn(GGPlotD());

Some examples can be found here:
https://blackedder.github.io/ggplotd/example.html
https://blackedder.github.io/ggplotd/ggplotd/ggplotd/GGPlotD.html

2 days ago

On Tuesday, 12 August 2025 at 07:18:45 UTC, Serg Gini wrote:

>
auto gg = xs.zip(ys)
            .map!((t) => aes!("x","y")(t[0], t[1]))
            .geomPoint.putIn(GGPlotD());

Some examples can be found here:
https://blackedder.github.io/ggplotd/example.html
https://blackedder.github.io/ggplotd/ggplotd/ggplotd/GGPlotD.html

Thanks for your reply. Finally I got it to work. The code is the following

import std.stdio;
import std.array;

import mir.ndslice;

import ggplotd.aes: aes, Aes;
import ggplotd.axes: xaxisLabel, yaxisLabel;
import ggplotd.ggplotd: GGPlotD, putIn;
import ggplotd.geom: geomPoint, geomBox, geomLine;

void main()
{
	auto x = [1.47f, 1.50f, 1.52f, 1.55f, 1.57f, 1.60f, 1.63f, 1.65f, 1.68f, 1.70f, 1.73f, 1.75f, 1.78f, 1.80f, 1.83f].sliced(15);
	auto y = [52.21f, 53.12f, 54.48f, 55.84f, 57.20f, 58.57f, 59.93f, 61.29f, 63.11f, 64.47f, 66.28f, 68.10f, 69.92f, 72.19f, 74.46f].sliced(15);

	auto xs = x.array;
	auto ys = y.array;

	auto a = Aes!(float[], "x", float[], "y")(xs, ys);
	auto gg = geomPoint(a).putIn(GGPlotD());
	gg.save("scatter.png");
}