Create a grid of pie charts with Pandas or Seaborn

Multi tool use
Create a grid of pie charts with Pandas or Seaborn
Given this DataFrame:
x = pd.DataFrame({"A": [11, 3, 7], "B": [4, 12, 8], "C": [5, 5, 5]}, index=["s1", "s2", "s3"] )
Corresponding to the grades of students s1, s2, and s3 over a semester. Student s1, for example, got 11 A's, 4 B's and 5 C's. There were 20 assignments total.
I would like to create a collection of small pie charts showing the proportions of A,B and C grades, for each students.
In my real data set I might have 80 students so I would like a grid of say 8 by 10 little tiny pie charts, labeled with the students Id.
I've pored over the docs, but I can't find a good elegant solution other than literally iterating with Python. But I feel there ought to be a nicer way.
When I used the dataset below (basically the same as above) and then try variations of this to create my grid of pies, the pies are always squashed in different directions.
df.T.plot.pie(subplots=True, figsize=[6,50], layout=[10,4], legend=False)
I can't make sense out of what fig size is doing. I've looked through the docs and plenty of Stack Overflow to help me understand the unites. Basically, the parameter seems to be ignored. Here's the data:
$ cat data.csv
,A,B,C,D
as9.2,31,0,0,0
as22.2,17,9,1,4
as21.1,16,15,0,0
as16.2,15,12,4,0
as17.1,12,15,4,0
as7.1,12,8,11,0
coursetotal,11,17,3,0
as22.1,11,17,1,2
as24.1,9,18,0,4
as22.9,7,5,0,0
as19.1,6,21,2,0
as18.2,6,18,5,2
as10.2,5,21,5,0
as14.2,4,23,4,0
as15.1,4,21,1,5
as20.1,4,16,9,2
as16.1,0,27,4,0
1 Answer
1
By using pandas
, layout
is to set up how many subplot you need in one line , here I am using 3
pandas
layout
x.T.plot.pie(subplots=True, figsize=(7, 2),layout=(1,3))
@pitosalas transpose :-)
– Wen
Dec 27 '17 at 3:52
Shortcut :) I thought I'd seen that before! Where are those documented?
– pitosalas
Dec 27 '17 at 3:53
@pitosalas for T pandas.pydata.org/pandas-docs/stable/generated/… for pie pandas.pydata.org/pandas-docs/stable/generated/…
– Wen
Dec 27 '17 at 3:55
Is there anything in seaborn to make it prettier?
– pitosalas
Dec 27 '17 at 12:37
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Cool. What's the T?
– pitosalas
Dec 27 '17 at 3:50