Saturday, December 29, 2012

Pie charting with gnuplot

In two of my previous posts (post-1 post-2), I have talked about how to plot a pie chart using gnuplot. This time I will introduce a new method witch is much more simpler.

This new method will use the plotstyle "circle". And this feather is not provide since gnuplot version 4.6. So you have to update your gnuplot to a version not lower than 4.6.

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

set size square
set xrange [-1:1]
set yrange [-1:1]
set style fill solid 1

unset border
unset tics
unset key

plot '-' with circle linecolor var
0 0 1 0   30  1
0 0 1 30  60  2
0 0 1 60  120 3
0 0 1 120 190 4
0 0 1 190 275 5
0 0 1 275 360 6
##the first two numbers 0 0 are the
# x and y coordinate of center
##the third number 1 is the radius
#of the circle
##the fourth and fifth number are the
#begin and end angle of the sector
##the last number is the color indicate

set output

Fig.1 Pie charting using gnuplot


  1. How would you label each slice?

    1. You can have a loot at where each slice is labeled.

    2. I did, and ended up just using your python script on that page to do what I needed. I'd really like to use the format on this page as it gives me a little more flexibility when I generate my dataset from the database, but I'm having a hard time getting labels to show up correctly.

      Thanks anyway.

    3. label example
      add 7th column to the data with the labels
      plot instruction could then be:

      set angles degrees
      plot 'datafile' u 1:2:3:4:5:6 with circles lc var, '' u (cos($3+(($4-$3)/2))):(sin($3+(($4-$3)/2))):7 with labels

  2. Great content, used this site for reference for gnuplot quite a bit. Any books or sites you recommend to get really familiar with gnuplot?


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.