Skip to content

Instantly share code, notes, and snippets.

@jasonmc
Created April 29, 2011 19:20
Show Gist options
  • Save jasonmc/948850 to your computer and use it in GitHub Desktop.
Save jasonmc/948850 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
def getFancyFig():
fig_width_pt = 240.0 # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27 # Convert pt to inch
golden_mean = (sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
params = {'backend': 'pdf',
'axes.labelsize': 8,#10,
'text.fontsize': 8,#10,
'legend.fontsize': 8,#10,
'xtick.labelsize': 8,
'ytick.labelsize': 8,
'font.family':'serif',
'font.serif':'Times',
'text.usetex': True,
'figure.figsize': fig_size}
plt.rcParams.update(params)
fig = plt.figure(figsize=fig_size)
#plt.axes([0.125,0.2,0.95-0.125,0.95-0.2])
return fig
def setFancyLegend(leg):
# the matplotlib.patches.Rectangle instance surrounding the legend
frame = leg.get_frame()
frame.set_facecolor('0.95') # set the frame face color to light gray
frame.set_edgecolor('0.40')
frame.set_linewidth(0.4)
# matplotlib.lines.Line2D instances
for l in leg.get_lines():
l.set_linewidth(1.5) # the legend line width
def plot2(d1,d2,labels,legends,fancy=False,outfilename=''):
if fancy:
fig = getFancyFig()
lw = 0.3
else:
fig = plt.figure()
lw = 1
ax = fig.add_subplot(111)
l1 = ax.plot(d1)
plt.setp(l1, color='k', linewidth=lw,aa=True)
ax.set_ylabel(labels[0])
ax2 = ax.twinx()
ax2.set_ylabel(labels[1])
l2 = ax2.plot(d2)
plt.setp(l2, color='#3E9435', linewidth=lw,aa=True)
leg = plt.legend([l1,l2],legends,'upper left', shadow=False)
if fancy and outfilename:
setFancyLegend(leg)
plt.savefig(outfilename,bbox_inches='tight')
else:
plt.show()
def plot3(d1,d2,d3,labels,legends,fancy,outfilename):
if fancy:
fig = getFancyFig()
lw = 0.3
else:
fig = plt.figure()
lw = 1
ax = fig.add_subplot(111)
l1 = ax.plot(d1)
plt.setp(l1, color='k', linewidth=lw,aa=True)
ax.set_ylabel(labels[0])
ax2 = ax.twinx()
ax2.set_ylabel(labels[1])
l2 = ax2.plot(d2)
plt.setp(l2, color='#3E9435', linewidth=lw,aa=True)
l3 = ax2.plot(d3)
plt.setp(l3, color='#B13F45', linewidth=lw,aa=True)
leg = plt.legend([l1,l2,l3],legends,'upper left', shadow=False)
if fancy and outfilename:
setFancyLegend(leg)
plt.savefig(outfilename,bbox_inches='tight')
else:
plt.show()
d1,d2,d3 = ...
labels = ('Execution time','Indirect branch misses executed')
legends = ('Execution time','L1-I misses','Indirect branch misses')
plot3(d1,d2,d3,labels,legends,fancy,'output.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment