How to plot a simple scatter plot using ggplotd
Marc
mailnawman at gmail.com
Tue Aug 12 09:21:52 UTC 2025
On Tuesday, 12 August 2025 at 07:18:45 UTC, Serg Gini wrote:
> ```d
> 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
```d
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");
}
```
More information about the Digitalmars-d-learn
mailing list