kplotCairo plotting library

This is an example usage of kplot, an ISO C, ISC-licensed UNIX programming library for plotting graphs on a Cairo surface. It handles drawing margins, axis labels, tic labels, tics, borders, grids, and the data itself. Data may be specified structurally as finite buckets, range histograms, arrays, and vectors. Data may also be computed from other sources, such as the mean and standard deviation.

#include <cairo.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <kplot.h>

int
main(void)
{
  struct kpair points1[50], points2[50];
  struct kdata *d1, *d2;
  struct kplot *p;
  cairo_surface_t *surf;
  size_t i;
  cairo_t *cr;

  for (i = 0; i < 50; i++) {
    points1[i].x = points2[i].x = (i + 1) / 50.0;
    points1[i].y = log((i + 1) / 50.0);
    points2[i].y = -log((i + 1) / 50.0) + points1[0].y;
  }
  d1 = kdata_array_alloc(points1, 50);
  d2 = kdata_array_alloc(points2, 50);
  p = kplot_alloc(NULL);
  kplot_attach_data(p, d1, KPLOT_POINTS, NULL);
  kplot_attach_data(p, d2, KPLOT_LINES, NULL);
  kdata_destroy(d1);
  kdata_destroy(d2);
  surf = cairo_image_surface_create
    (CAIRO_FORMAT_ARGB32, 600, 400);
  cr = cairo_create(surf);
  cairo_surface_destroy(surf);
  kplot_draw(p, 600.0, 400.0, cr);
  cairo_surface_write_to_png
    (cairo_get_target(cr), "example0.png");
  cairo_destroy(cr);
  kplot_free(p);
  return(EXIT_SUCCESS);
}

For a complete reference, consult kplot(3). Download sources from kplot.tgz (current version 0.1.15, sha512) or browse the archive. If you'd like to contribute, please contact Kristaps directly, or use the GitHub/kplot page. The source has been tested on OpenBSD, FreeBSD, NetBSD, Mac OS X, and various Linux distributions. kplot is a BSD.lv project.