import pandas as pd
import matplotlib.pyplot as pl
#import seaborn as sns

from categorize import CATEGORIES

FLAT = ["#1abc9c", "#2ecc71", "#3498db", "#9b59b6",
"#f1c40f", "#e67e22", "#e74c3c", 
"#16a085", "#27ae60", "#2980b9", "#8e44ad",
         "#f39c12", "#d35400", "#c0392b"]

FLAT = ["#2ecc71", "#27ae60"]

df = pd.read_csv("k2-categories.csv", names=["bibcode", "category"])

# Simplify the pie chart by mergin certain categories
CATEGORIES['cl'] = "Open Clusters"
df.loc[df.category == 'ro', 'category'] = 'cl'
CATEGORIES['da'] = "Catalogs & Data Analysis"
df.loc[df.category == 'ca', 'category'] = 'da'
CATEGORIES['ot'] = "Extragalactic & Other Science"
df.loc[df.category == 'cv', 'category'] = 'ot'
#CATEGORIES['as'] = "Asteroseismology"
#df.loc[df.category == 'ga', 'category'] = 'as'

counts = df.category.value_counts()
myorder = ['ed', 'ec', 'ml', 'as', 'ga', 'va', 'wd', 'cl', 'eb', 'yo', 'ac', 'ss', 'ot', 'da']
assert(len(myorder) == len(counts.index))

labels = [CATEGORIES[lab] for lab in myorder]
sizes = [counts[lab] for lab in myorder]

#sizes = counts.values

fig1, ax = pl.subplots(figsize=(16, 9))
ax.pie(sizes, labels=labels, autopct='%1.0f%%', startangle=145,
       counterclock=False, colors=FLAT,
       pctdistance=0.8, labeldistance=1.1,
       textprops={'fontsize': 20, 'weight': 'bold'})
ax.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.
pl.tight_layout(rect=[0.05, 0.05, 0.95, 0.95])
pl.savefig("k2-science-piechart.png")

@@ -1,12 +1,97 @@
+%22%22%22Make a pie chart plot showing the distribution of K2 papers by science theme.%0A%22%22%22%0A
 import panda
@@ -132,31 +132,8 @@
 s pl
-%0A#import seaborn as sns
 %0A%0Afr
@@ -169,211 +169,8 @@
 ES%0A%0A
-FLAT = %5B%22#1abc9c%22, %22#2ecc71%22, %22#3498db%22, %22#9b59b6%22,%0A%22#f1c40f%22, %22#e67e22%22, %22#e74c3c%22, %0A%22#16a085%22, %22#27ae60%22, %22#2980b9%22, %22#8e44ad%22,%0A         %22#f39c12%22, %22#d35400%22, %22#c0392b%22%5D%0A%0AFLAT = %5B%22#2ecc71%22, %22#27ae60%22%5D%0A
 %0Adf 
@@ -825,16 +825,91 @@
 ndex))%0A%0A
+#labels = %5BCATEGORIES%5Blab%5D for lab in counts.index%5D%0A#sizes = counts.values%0A
 labels =
@@ -992,36 +992,11 @@
 r%5D%0A%0A
-#sizes = counts.values%0A%0A
 fig
-1
 , ax
@@ -1129,12 +1129,30 @@
 ors=
-FLAT
+%5B%22#2ecc71%22, %22#27ae60%22%5D
 ,%0A  
@@ -1370,16 +1370,16 @@
  0.95%5D)%0A
-
 pl.savef
@@ -1408,8 +1408,24 @@
 t.png%22)%0A
+pl.close(%22all%22)%0A

Clean up script