import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.colors
import sys

# change font family to match math
#plt.rc('font', family='serif')

fontsize = 18
font = {'family' : 'sans-serif',
#        'serif' : 'Times Regular',
        'size'   : fontsize}
matplotlib.rc('font', **font)

output_dir = "plots"

# load in data
data_fname = sys.argv[1]

labels = np.unique(np.loadtxt(data_fname, usecols=[2], dtype='str'))

print labels

data = np.loadtxt(data_fname, converters = {2: lambda y: np.where(labels==y)[0]})

print data

recall_idx = 0
precision_idx = 1
model_idx = 2

# initialize figures
fig1 = plt.figure()
ax1 = fig1.add_subplot(111)
ax1.set_title("Recall vs. Precision", fontsize=fontsize)
ax1.set_xlabel("Recall")
ax1.set_ylabel("Precision")
for i in range(len(labels)):
	indices = np.where(data[:,model_idx] == i)
	ax1.plot(data[indices,recall_idx][0], data[indices,precision_idx][0], label=labels[i])

ax1.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, pos: ('%.2f')%(y)))

# add legend
ax1.legend()

#fig1.savefig("%s/compare-accuracy-speed-margin.pdf" % (output_dir), bbox_inches='tight')

plt.show()

add python script to plot p/r curve