Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm plotting disk partitioning and available space.

I have a pie chart showing the partitioning: e.g. 30% /, 70% /home.

In the second ring I want to show that 90% / is full, 10% of / is empty. 10% /home is full, 90% /home is empty.

How can I generate the 'second' series of the wedges?

Please give example in LibreOffice, gnuplot, matplotlib, etc.

Something like this:

enter image description here

share|improve this question
2  
Perhaps stop aiming for a "Pie chart" and start looking into a "Radial tree" or "Ring chart"? –  techie007 Jan 31 '12 at 15:18
    
@techie007 sure. So how do I create one on Linux? –  Dima Jan 31 '12 at 15:36
add comment

2 Answers

up vote 3 down vote accepted

Assume your data is in the format:

data = {
    # partition: (frac of disk, frac full)
    "/": (0.3, 0.9),
    "/home": (0.7, 0.1),
}

Try using the reportlab.graphics library (available from the Ubuntu and Fedora repositories as python-reportlab):

from reportlab.graphics.shapes import Drawing
from reportlab.graphics.charts.piecharts import Pie
from reportlab.graphics import renderSVG
from itertools import chain
d = Drawing(400, 400)

outerPie = Pie()
outerPie.x = outerPie.y = 0
outerPie.width = outerPie.height = 400
# 2 slices for each sector (used, unused)
outerPie.data = list(chain(*[
    [fracDisk * fracPart, fracDisk * (1 - fracPart)]
    for (fracDisk, fracPart) in data.values()]))
d.add(outerPie, '')

# Draw smaller pie chart on top of outerPie, leaving outerPie as a ring
innerPie = Pie()
innerPie.x = innerPie.y = 100
innerPie.width = innerPie.height = 200
innerPie.data = [t[0] for t in data.values()]
innerPie.labels = list(data)
d.add(innerPie, '')

renderSVG.drawToFile(d, 'chart.svg')

Sample output:

Sample output of chart

share|improve this answer
add comment

It can also be done quite simply in Mathematica (tested on the Linux version):

data = {{"/", 0.3, 0.9}, {"/home", 0.7, 0.1}};
PieChart[{
  Labeled[#[[2]], #[[1]]] & /@ data,
  Flatten[{Labeled[#[[2]] *    #[[3]] , "used"], 
           Labeled[#[[2]] * (1-#[[3]]), "free"]} & /@ data]
}, SectorSpacing -> 0]

Or if you want the colors to match:

data = {{"/", 0.3, 0.9, Red}, {"/home", 0.7, 0.1, Blue}};
PieChart[{
  Style[Labeled[#[[2]], #[[1]]], #[[4]]] & /@ data,
  Flatten[{Style[Labeled[#[[2]] *    #[[3]] , "used"], #[[4]]], 
           Style[Labeled[#[[2]] * (1-#[[3]]), "free"], Lighter@#[[4]]]} & /@ data]
}, SectorSpacing -> 0]

Pie chart

share|improve this answer
    
awesome! now same using opensource tools? =) –  Dima Aug 1 '12 at 15:57
    
@Dima: reportlab.graphics is open-source. –  Mechanical snail Aug 1 '12 at 15:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.