Friday, November 30, 2012

Plot a pie chart using gnuplot

If your gnuplot version is not lower than 4.4, then plotting a pie chart can be done with command "set object circle...". The following is an example.

reset
set term postscript eps color enhanced size 5cm,5cm
set output "pie_chart.eps"

set size square
set style fill solid 1.0 border -1

set object 1 circle at screen 0.5,0.5 size \
  screen 0.45 arc [0   :50  ] fillcolor rgb "red" front
set object 2 circle at screen 0.5,0.5 size \
  screen 0.45 arc [50  :150] fillcolor rgb "orange" front
set object 3 circle at screen 0.5,0.5 size \
  screen 0.45 arc [150:220] fillcolor rgb "forest-green" front
set object 4 circle at screen 0.5,0.5 size \
  screen 0.45 arc [220:360] fillcolor rgb "dark-magenta" front

#plot a white line, i.e., plot nothing
unset border
unset tics
unset key
plot x with lines lc rgb "#ffffff"
set output

Fig.1 Plot a pie chart using gnuplot

If you think setting of the position, size and arc manually is very tedious, you may write a script with any programming language.

Follow this link to see a new simpler method to plot a pie chart.


Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.