Skip to content

Instantly share code, notes, and snippets.

@guanhuamai
Last active March 14, 2017 07:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save guanhuamai/043dabe6263829cea39d1245feb957f1 to your computer and use it in GitHub Desktop.
Save guanhuamai/043dabe6263829cea39d1245feb957f1 to your computer and use it in GitHub Desktop.
PyDraw
import re
import matplotlib.pyplot as plt
import numpy as np
class ResultReader:
def __init__(self):
self.lines = list()
self.op = ""
self.dataName = ""
self.algoData = {"defaultTree": dict(), "fbsTree": dict(),
"starTree": dict(), "strTree": dict()}
self.algoFormat = {"defaultTree": "ro-", "fbsTree": "b^-",
"starTree": "bs-", "strTree": "yo-"}
def read(self, path):
with open(path, 'r') as f:
self.lines = f.readlines()
def get_match(self):
for l in self.lines:
for k in self.algoData:
patM = "(?<=" + k + self.dataName + "M).*(?=" + self.op + ")"
if not (self.dataName in l and k in l and self.op in l):
continue
m = int(re.search(patM, l).group(0))
s = float(str(re.search("[0-9]+\.[0-9]+(?= \$)", l).group(0))) # please change the '+-' sign into '$' first
self.algoData[k][m] = s
break
def draw(self, save, filename):
fig, ax = plt.subplots()
for algo in self.algoData:
xaxis = list()
yaxis = list()
for k in self.algoData[algo]:
xaxis.append(k)
yaxis.append(self.algoData[algo][k])
ax.plot(np.array(xaxis), np.array(yaxis), self.algoFormat[algo], label=algo)
legend = ax.legend(loc='upper center', shadow=True, fontsize='x-large')
legend.get_frame().set_facecolor('#00FFCC')
if save:
plt.savefig(filename)
else:
plt.show()
if __name__ == "__main__":
opList = ["Construction", "SearchOne", "SearchNearest", "InsertOne", "InsertBatch", "DeleteOne", "DeleteBatch", ]
dataList = ["1k", "Greek"]
rr = ResultReader()
rr.read("rtreeexp.txt")
for _op in opList:
for _ds in dataList:
rr.op = _op
rr.dataName = _ds
rr.get_match()
rr.draw(True, _op + "." + _ds + ".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment