An SWI Prolog library to plot ggplot2 charts for Cplint on SWISH
This repository has been archived on 2021-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Fabrizio Riguzzi b4432bb028 Merge pull request #5 from friguzzi/master
test_r in cplint_r
2017-07-05 14:43:40 +02:00
doc Updated readme. 2017-01-30 19:24:24 +01:00
images Added picture as example. 2017-01-21 19:05:56 +01:00
prolog test_r meta 2017-07-04 16:54:54 +02:00
tests Fixed tests due to API change. 2017-01-30 19:20:49 +01:00
.gitignore Updated documentation. Added most external makefile. 2016-12-09 13:32:42 +01:00
LICENSE Added files. 2016-11-28 20:33:06 +01:00
Makefile Fixed copyright headers. Added script that updates library version on manual. 2017-01-10 16:41:59 +01:00 Updated readme. 2017-01-30 19:24:24 +01:00 Removed unnecessary labels from charts. 2017-01-29 15:36:57 +01:00


An SWI Prolog library to plot ggplot2 charts for Cplint on SWISH.


This library is to be used with Cplint on SWISH.

At the moment, it is included as part of the installation process in the swish-cplint package for the Arch GNU/Linux distribution (and derivatives).

The structure of this repository follows (more or less) some interesting guidelines written by Raivo Laanemets.


Taken from here

Mixture of two Gaussians. A biased coin is thrown, if it lands heads X in 
is sampled from a Gaussian with mean 0 and variance 1. if it lands tails X is
sampled from a Gaussian with mean 5 and variance 2.
The example illustrates the use of continuous random variables and
the use of sampling, including
rejection sampling and Metropolis/Hastings. Moreover the example
illustrates the use of the predicate histogram/2 for graphing the
probability density function of continuous random variables.
:- use_module(library(mcintyre)).
:- use_module(library(cplint_r)).

:- mc.
:- begin_lpad.

% a coin is thrown. The coin is biased: with probability 0.6 it lands heads,
% with probabiity 0.4 it lands tails

g(X): gaussian(X,0, 1).
% X in g(X)  follows a Gaussian distribution with mean 0 and variance 1
h(X): gaussian(X,5, 2).
% X in h(X)  follows a Gaussian distribution with mean 5 and variance 2

mix(X) :- heads, g(X).
% if the coin lands heads, X in mix(X) is given by g(X)
mix(X) :- tails, h(X).
% if the coin lands tails, X in mix(X) is given by h(X)

:- end_lpad.

% take SAmples samples of X in mix(X) and draw a histogram with NBins bins 
% the probability density of X 

The query

?- hist_uncond(10000,40).

Gives the following



?- pack_install('cplint_r').

Full documentation (including API)

Running tests

In the package root, execute into swipl:

?- [tests/tests].
?- run_tests.

or, if you cloned the repo:

$ make test


2017-01-30 version 1.0.0. API change. Rendering improvement in density functions. Lots of fixes.

2017-01-13 version 0.0.3. Fixed minor issues.

2017-01-13 version 0.0.2. Fixed densities_r/3. Better error handling.

2017-01-07 version 0.0.1. First release including documentation.


  • Unable to view the plots within swipl. It should be possible to save a pdf file of the corresponding plot anyway.


Copyright (c) 2016-2017 Franco Masotti (

This is free software: you can redistribute it and/or modify it under the terms of the Artistic License 2.0 as published by The Perl Foundation.

This source is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Artistic License 2.0 for more details.

You should have received a copy of the Artistic License 2.0 along the source as a LICENSE file. If not, obtain it from