2013-06-13 24 views
0

我有一個下面的代碼產生的圖形 - 在劇情matplotlib長傳奇的名字

# imports specific to the plots in this example 
import sys 
import numpy as np 
from matplotlib import cm 
import matplotlib.pyplot as plt 

resultsDirectory='results' 

outputFile=resultsDirectory+".pdf" 
axisLabelFontSize=16 
borderWidth=0.0 

# Twice as wide as it is tall. 
fig = plt.figure(figsize=plt.figaspect(0.5)) 
ax = fig.add_subplot(111) 

# Set up the Grid 
[i.set_linewidth(borderWidth) for i in ax.spines.itervalues()] 


unsatX=[680,2775,3821,680,4073,941,1202,1463] 
unsatY=[1,1,1,4,1,2,2,2] 
paretoX=[680, 1203, 1726, 4870] 
paretoY=[10,7, 4,1] 
satX=[4870,680,1727,1726,1203,680] 
satY=[1,13,7,4,7,10] 
typeX=[680, 1727] 
typeY=[13, 7] 
leftX=[680] 
leftY=[12] 

c = np.rec.fromarrays([paretoX, paretoY], names='x,y') 
c.sort() 
paretoX=c.x 
paretoY=c.y 

markrsz=8 
l4, = plt.plot(paretoX, paretoY, '#000000', lw=2, label='Pareto Curve(unfolding, period locality)',markersize=markrsz,zorder = 10) 
l1, = plt.plot(satX, satY, 'bo', label='Sat Points',markersize=markrsz,zorder = 10) 
l2, = plt.plot(unsatX, unsatY, 'ro',marker='s',label='Unsat Points',markersize=markrsz,zorder = 10) 
l5, = plt.plot(leftX, leftY, 'gp',label='Proc. count pareto points',markersize=markrsz) 
l6, = plt.plot(typeX, typeY, 'w*',label='Modulo pareto points',markersize=markrsz,zorder=10) 


leg=plt.legend(bbox_to_anchor=(0.,-0.200, 1., 1.102), loc=3, numpoints=1, 
     ncol=3, mode="expand", borderaxespad=0., fancybox=True, shadow=True,prop={'size':axisLabelFontSize}) 

rect = leg.get_frame() 
rect.set_facecolor('#cccccc') # a grayscale intensity 
#leg.set_frame_on(False) 

latency=[680,2775,4870, 680,3821,4868, 680,1727,4341,4864, 680,1203,1726,1203, 680,4073,4334,4595,4856, 941,1202,1463,1724] 
processor=[1, 1, 1,13, 1, 1, 7, 7, 1, 1, 4, 4, 4, 7,10,1, 1, 1, 1, 2, 2, 2, 2] 

ax.set_xlabel('Period',size=axisLabelFontSize,labelpad=10) 
ax.set_ylabel('Processors',size=axisLabelFontSize,labelpad=10) 
ax.set_xlim(0, max(latency)+100) 
ax.set_ylim(0, max(processor)+1) 

# Set Border width zero 
[i.set_linewidth(0) for i in ax.spines.itervalues()] 

gridLineWidth=0.1 
ax.set_axisbelow(False) 
gridlines = ax.get_xgridlines()+ax.get_ygridlines() 
#ax.set_axisbelow(True) 

plt.setp(gridlines, 'zorder', 5) 

ax.yaxis.grid(True, linewidth=gridLineWidth, linestyle='-', color='0.6',alpha='0.3') 
ax.xaxis.grid(False) 
ax.xaxis.set_ticks_position('none') 
ax.yaxis.set_ticks_position('none') 

fig.savefig(outputFile, format="pdf", bbox_inches='tight') 

傳說搞的一團糟。 有人能告訴我如何修復一個覆蓋到其他項目區域的長圖例條目?如果我可以在第一行做三個圖例條目,在第二行做兩個圖例條目,那麼這將是理想的。

enter image description here

+0

什麼d你的意思是「修復一個長傳說名字」 –

+0

我的意思是它覆蓋在另一個傳說的領域。 – Raj

+0

以下修改代碼可以暫時解決我的問題 - 'leg = plt.legend(bbox_to_anchor =(0.350,1.1102),loc = 3,numpoints = 1,ncol = 2,borderaxespad = 0.,fancybox = True,shadow = True,prop = {'size':axisLabelFontSize})' – Raj

回答

3

除了對這個問題筆者發現瞭解決方法,有可能是添加新的線長標籤:

... 
l4, = plt.plot(paretoX, paretoY, '#000000', lw=2, 
    label='Pareto Curve \n(unfolding, period locality)',markersize=markrsz,zorder = 10) 
... 

enter image description here

1

以下修改的代碼也解決了我問題 -

leg=plt.legend(bbox_to_anchor=(0.,-0.350, 1., 1.102), loc=3, numpoints=1, ncol=2 , borderaxespad=0., fancybox=True, shadow=True,prop={'size':axisLabelFontSize})