Reputation: 1148
Why is the first boxplot missing? There's supoussed to be 24 boxplots, but only 23 are being display as you can see in the image. Who's size do i have to change to make it visible? I've tried changing the size of the figure but its the same.
Not sure if it helps, but this is the code:
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' )
Upvotes: 0
Views: 568
Reputation: 2071
Your boxplot is there but it's hidden. This reproduces your problem:
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()
Notice that you are defining your positions as ranging from 0 to 12, but you append ticks
as range(0,12) + 0.5
. Thus, when you later do set_xticks(ticks)
, your x axis will begin from 0.5 but your 1st boxplot is plotted at position 0.
I've adapted your code slightly to produce the result you want:
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()
Upvotes: 1