Skip to content

Commit

Permalink
enhance lisibility, split if statement on 2 lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycojoker committed Jun 3, 2012
1 parent 5e668b1 commit 45ef18a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def __init__(self, title='title', xlab='x', ylab='y', xrange=None, yrange=None):
self.ax.set_title(title)
self.ax.set_xlabel(xlab)
self.ax.set_ylabel(ylab)
if xrange: self.ax.set_xlim(xrange)
if yrange: self.ax.set_ylim(yrange)
if xrange:
self.ax.set_xlim(xrange)
if yrange:
self.ax.set_ylim(yrange)
self.legend = []

def save(self, filename='plot.png'):
Expand All @@ -28,23 +30,27 @@ def save(self, filename='plot.png'):
FigureCanvasAgg(self.fig).print_png(s)
return s.getvalue()

def binary(self): return self.save(None)
def binary(self):
return self.save(None)

def hist(self, data, bins=20, color='blue', legend=None):
q = self.ax.hist(data,bins)
if legend: self.legend.append((q[0],legend))
if legend:
self.legend.append((q[0],legend))
return self

def plot(self, data, color='blue', style='-', width=2, legend=None):
x,y = [p[0] for p in data], [p[1] for p in data]
q = self.ax.plot(x,y,linestyle=style,linewidth=width,color=color)
if legend: self.legend.append((q[0],legend))
if legend:
self.legend.append((q[0],legend))
return self

def errorbar(self, data, color='black', marker='o', width=2, legend=None):
x,y,dy = [p[0] for p in data], [p[1] for p in data], [p[2] for p in data]
q = self.ax.errorbar(x,y,yerr=dy,fmt=marker,linewidth=width,color=color)
if legend: self.legend.append((q[0],legend))
if legend:
self.legend.append((q[0],legend))
return self

def ellipses(self, data, color='blue', width=0.01, height=0.01):
Expand Down

0 comments on commit 45ef18a

Please sign in to comment.