Making a Venn diagram with pic and PostScript

Last-Updated: 2022-01-04

Sources

Simple Venn diagrams

Simple Venn diagrams can be obtained with pic only with the following instructions written by Berend Tober (2016-10/msg00009).

Instructions for (A - B)

.po 0.35i
.PS
move 
{A: circle invisible fill rad 1.2}
move right 0.5
B: circle invisible fill 0 rad 1.4
.ps +10
move to A
move up 0.8
move left 0.35
"milk"
move left 0.2
move down  0.3
"juice"
move left .35
move down  0.35
"jam"
.PE

Instructions for (B - A)

.po 0.35i
.PS
move 
{move right 0.5
B: circle invisible fill rad 1.4
}     
{A: circle invisible fill 0 rad 1.2}
.ps +10
move to B
move up 1
move right 0.3
"butter"
move down 0.35
move right .2
"bacon"
move down 0.35
move right 0.15
"sausage"
move down 0.35
"ham"
.PE

A more complex Venn diagram: the symmetric difference

The symmetric difference of A and B is the set of elements which are in A or B but not in A and B.

The representation of such a set was proved possible thanks to Tadziu Hoffmann with the following snippet which combines pic and PostScript (2016-10/msg00011). These instructions are only valid for groff with the PostScript device.

.PS
"\X'ps: exec grops begin /DA { newpath arcn gsave } def end'"
arc at -.5,0 from 0,1 to 0,-1 colored "lightgray"
"\X'ps: exec grops begin /DA { grestore arc fill } def end'"
arc at  .5,0 from 0,-1 to 0,1
"\X'ps: exec grops begin /DA { newpath arcn gsave } def end'"
arc at  .5,0 from 0,-1 to 0,1
"\X'ps: exec grops begin /DA { grestore arc fill } def end'"
arc at -.5,0 from 0,1 to 0,-1
"\X'ps: exec grops begin /DA { newpath arcn stroke } def end'"
circle at -.5,0 radius sqrt(1.25) outline "black"
circle at  .5,0 radius sqrt(1.25)
.PE
← Go back