The piechart command produces piecharts based upon single columns of data read from datafiles, which are taken to indicate the sizes of the pie wedges. The piechart command has the following syntax:
piechart ('<filename>'|<function>) [using <using specifier>] [select <select specifier>] [index <index specifier>] [every <every specifier>] [label <auto|key|inside|outside> <label>] [format <format string>] [with <style> [<style modifier> ... ] ]
Immediately after the piechart keyword, the file (or indeed, function) from which the data is to be taken should be specified; any of the modifiers taken by the plot command – i.e. using, index, etc. – may be used to specify which data from this datafile should be used. The label modifier should be used to specify how a name for each pie wedge should be drawn from the datafile, and has a similar syntax to the equivalent modifier in the plot command, except that the name string may be prefixed by a keyword to specify how the pie wedge names should be positioned. Four options are available:
auto – specifies that the inside positioning mode should be used on wide pie wedges, and the outside positioning mode should be used on narrow pie wedges. [default]
key – specifies that all of the labels should be arranged in a vertical list to the right-hand side of the piechart.
inside – specifies that the labels should be placed within the pie wedges themselves.
outside – specifies that the labels should be arranged around the circumference of the pie chart.
Having specified a name for each wedge using the label modifier, the format modifier determines the final text which is printed along side each wedge. For example, a wedge with name ‘Europe’ might be labelled as ‘27% Europe’, applying the default format string:
"%.1d\%% %s"%(percentage,label)
Three variables may be used in format strings: label contains the name of the wedge as specified by the label modifier, percentage contains the numerical percentage size of the wedge, and wedgesize contains the absolute unnormalised size of the wedge, as read from the input datafile, before the sizes were renormalised to sum to 100%.
The with modifier may be followed by the keywords colour, linewidth, style, which all apply to the lines drawn around the circumference of the piechart and between its wedges. The fill colour of the wedges themselves are taken sequentially from the current palette, as set by the set palette command. Note that PyXPlot’s default palette is optimised more for producing plots with datasets in different and distinct colours than for producing piecharts in aesthetically pleasing shades, where a little more subtly may be desirable. A suitable call to the set palette command is highly recommended before the piechart command is used.
As with the plot command, the position and size of the piechart are governed by the set origin and set size commands. The former determines where the centre of the piechart is positioned; the latter determines its diameter.
A piechart of the composition of the Universe.
In this example, we use PyXPlot’s piechart command to produce a diagram of the composition of the Universe, showing that of the mass in the Universe, only 4% is in the form of the baryonic matter; of the rest, 22% is in the form of dark matter and 74% in the form of dark energy: |
set palette grey40, grey60, grey80 |
![]() |
Below, we show the change produced by replacing the line |
![]() |