A tiny plotting library for D, built on tiny-svg. Supports line plots, scatter plots, bar charts, histograms, and pie charts.
Add library to your project using DUB:
dub add tiny-plot
import rk.tplot;
auto p = Plot(800, 500);
double[] x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
double[] y = [2.3, 4.1, 3.5, 6.2, 5.8, 7.1, 8.3, 7.9, 9.2, 10.1];
p.plot(x, y, "Temperature");
p.setTitle("Line Plot Example");
p.setXLabel("Day");
p.setYLabel("Value");
p.save("line_plot.svg");All chart types are methods on a single Plot struct:
| Method | Description |
|---|---|
p.plot(x, y, name) |
Line plot |
p.scatter(x, y, name) |
Scatter plot |
p.bar(x, y, name) |
Bar chart |
p.hist(data, numBins, name) |
Histogram |
p.pie(values, names) |
Pie chart |
Additional methods:
p.setTitle(title)— set plot titlep.setXLabel(label)/p.setYLabel(label)— set axis labelsp.setStyle(style)— customize plot appearancep.save(filename)— render and save to SVG
Multiple series can be combined on the same plot:
auto p = Plot(900, 600);
p.bar(x, bars, "Volume");
p.plot(x, trend, "Trend");
p.scatter(x, actual, "Actual");
p.setTitle("Combined Plot");
p.save("combined_plot.svg");Code can be found here.
All code is licensed under the MIT license.
