3

This is my MetaPost input file:

prologues := 3 ;
outputformat := "%j-%c.eps" ;

input piechartmp;

beginfig(1);
  SetupColors((0.7, 0.7), this, this) ;
  SetupPercent(this, "%") ;

  Segment(64, "acc") ; 
  Segment(24, "bak") ;
  Segment(12, "ext") ;

  SegmentState(3, this, 0.3) ;

  PieChart(2cm, 0.15, 60, 0,0) ;

  Label.auto(0) (name) (outwards, 0) ;
  Label(1)(percent) (inwards, 0) withcolor (1, 1, 0) ;
  Label(2)(percent) (inwards, 0) withcolor (1, 1, 0) ;
  Label(3)(percent) (inwards, 0) withcolor (1, 1, 0) ;

  pickup pencircle scaled 2pt;
endfig;

end.

This is my makefile:

NAME=piechart
PDFVIEWER=acroread

all :
    mptopdf ${NAME}.mp
    mv -f ${NAME}.1 ${NAME}.eps
    mv -f ${NAME}-1.pdf ${NAME}.pdf
    ${PDFVIEWER} ${NAME}.pdf &

This is the output

enter image description here

I want to change 2 things:

1) I want the pie "ext" to be drawn lower than the rest. How do you do that?

2) I don't want "64%" for internal label of acc, I want the string 64% - 269 GiB. How to do that?

4
  • I don't think you can "lower" slices - but the comprehensive manual will tell you for sure. Changing the labels is in section 3.4
    – Thruston
    Nov 26, 2015 at 0:05
  • your outputformat line is doing nothing by the way - you can delete it. If you wanted to produce an .eps file directly use outputtemplate which has superseded the old command. But with your makefile you don't need it.
    – Thruston
    Nov 26, 2015 at 0:06
  • 1
    Random comment: 3d pie charts are generally considered less useful than the 2d version because the 3d perspective distorts the relative sizes of the slices. Nov 26, 2015 at 1:13
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Jan 6, 2018 at 21:09

1 Answer 1

6

Personally I would set such a simple data set as a plain table rather than a pie chart, but assuming we do want to do this as a pie chart, I recommend reading the manual available on CTAN carefully.

Here's a slightly simpler way to achieve what I think you might want:

prologues := 3 ;
outputtemplate := "%j-%c.eps";

input piechartmp;

beginfig(1);
label(btex \bf Your Title Here etex, (0,2cm));

  SetupColors((0.7, 0.7), this, this) ;
  SetupText(1,"","")
  SetupPercent(this, "\%");
  SetupValue(this, "\thinspace GiB");

  Segment(269, "acc") ;   
  Segment(100, "bak") ;
  Segment( 50, "ext") ;

  SegmentState(3, this, 0.4) ;

  PieChart(2.5cm, 0.15, 60, 290,0) ;

  Label.auto(0)(name) (inwards, 0) withcolor red+green;
  Label.auto(0)(percent,"${}\simeq{}$", value) (outwards,0);

endfig;
end.

This produces:

enter image description here

Notes

  • to make a title, just use a normal MP label command. But use it before doing the rest of the pie chart. For reference, the centre of the pie is at point (0,0).

  • give the real values in the Segment commands -- it will work out the percentages automatically

  • use SetupText(1,"","") to typeset the labels with TeX

  • use SetupValue to add a suffix to the data values

  • use SetupPercent to add a suffix to the calculated percentage value

  • combine percent and value as shown to make the label you want

  • put long labels outside the pie slices and short ones inside

  • use the fourth parameter to Piechart to rotate the whole chart -- this has the side effect of making the separated slice come to the front and hence to appear lower

  • read manual available on CTAN

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .