2015-09-28 42 views
0

为什么第一个boxplot丢失?有超过24个箱子,但只有23个正在显示,如图所示。 谁的身材我必须改变才能看到?我试过改变图的大小,但它是一样的。第一个boxplot丢失或不可见

Enero Boxplot is out of the square figure

不知道是否有帮助,但是这是代码:

def obtenerBoxplotsAnualesIntercalados(self, directorioEntrada, directorioSalida): 
    meses = ["Enero","Febrero","Marzo","Abril","Mayo","Junio", "Julio", "Agosto","Septie.","Octubre","Noviem.","Diciem."] 
    ciudades = ["CO","CR"]  
    anios = ["2011", "2012", "2013"] 
    for anio in anios: 
     fig = plt.figure() 
     fig.set_size_inches(14.3, 9) 
     ax = plt.axes() 
     plt.hold(True) 
     bpArray = [] 
     i=0 
     ticks = [] 
     for mes in range(len(meses)): 
      archivoCO = open(directorioEntrada+"/"+"CO"+"-"+self.mesStr(mes+1)+"-"+anio, encoding = "ISO-8859-1") 
      archivoCR = open(directorioEntrada+"/"+"CR"+"-"+self.mesStr(mes+1)+"-"+anio, encoding = "ISO-8859-1") 
      datosCOmes = self.obtenerDatosmensuales(archivoCO) 
      datosCRmes = self.obtenerDatosmensuales(archivoCR) 
      data = [ [int(float(datosCOmes[2])), int(float(datosCOmes[0])), int(float(datosCOmes[1]))], 
         [int(float(datosCRmes[2])), int(float(datosCRmes[0])), int(float(datosCRmes[1]))] ] 
      bpArray.append(plt.boxplot(data, positions=[i,i+1], widths=0.5)) 
      ticks.append(i+0.5) 
      i=i+2 
     hB, = plt.plot([1,1],'b-') 
     hR, = plt.plot([1,1],'r-') 
     plt.legend((hB, hR),('Caleta', 'Comodoro')) 
     hB.set_visible(False) 
     hR.set_visible(False) 
     ax.set_xticklabels(meses) 
     ax.set_xticks(ticks) 
     self.setBoxColors(bpArray) 
     plt.title('Variación de temperatura mensual Caleta Olivia-Comodoro Rivadavia. Año '+anio) 
     plt.savefig(directorioSalida+"/asdasd"+str(anio)+".ps", orientation='landscape', papertype='A4') 

回答

1

你箱线图是有,但它是隐藏的。此重现您的问题:正在定义为从0到12的位置

import matplotlib 
import numpy as np 

data = np.random.normal(10,2,100*24).reshape(24,-1) # let's get 12 pairs of arrays to plot 
meses = ["Enero","Febrero","Marzo","Abril","Mayo","Junio", "Julio", "Agosto","Septie.","Octubre","Noviem.","Diciem."] 

ax = plt.axes() 
plt.hold(True) 

i=0 

ticks = [] 

for mes in range(0,len(meses)): 
    plt.boxplot(data, positions=[i,i+1], widths=0.5) 
    ticks.append(i+0.5) 
    i+=2 

ax.set_xticklabels(meses) 
ax.set_xticks(ticks)  

plt.show() 

通知,但是你追加ticksrange(0,12) + 0.5。因此,当你以后做set_xticks(ticks),你的x轴从0.5开始,但你的第一箱线图在位置绘制0

wrong

我已经适应你的代码稍微产生你想要的结果:

ax = plt.axes() 
plt.hold(True) 

i=1 # we start plotting from position 1 now 

ticks = [] 

for mes in range(0,len(meses)): 
    plt.boxplot(data, positions=[i,i+1], widths=0.5) 
    ticks.append(i+0.5) 
    i+=2 

ax.set_xticklabels(meses) 
ax.set_xlim(0,ticks[-1]+1) # need to shift the right end of the x limit by 1 
ax.set_xticks(ticks)  


plt.show() 

fixed

+0

你的答案是优秀的!谢谢 – Hernan