I am trying to construct a plot where I have a fixed number of rows but differing number of columns for each row. The code I use for plotting is equivalent to:
import matplotlib.pyplot as pl
pl.figure()
pl.ion()
pl.subplot(2,1,1)
pl.title("Sets the title for top plot")
plotData(data[0]) # Function that plots data in this first row
for i in range(3):
pl.subplot(2,3,4+i)
pl.title("Sets the title of each subplot in second row")
plotData(data[i+1]) # Plots the data in second row
Now for some reason the data plotted in the subplots of the second row disappears. When I debug it it seems as it is there until returning from the plotData() function within the for-loop (or possibly upon calling
the next subplot command – but this does not explaing why the last subplot is empty …).
EDIT:
There was code at the end of the plotData() function that triggered the problem:
pl.gca().set_xlim(0,15)
pl.gca().set_ylim(0,15)
Does this mean that I can not set the x,y-limits after plotting the data, or what am I doing wrong here?
A pastebin of the minimal example showing the problem can be found here
OK, that was embarrassing. If you take a look at the code on pastebin the problem was that the xlim and ylim that I was setting did not take into account the fact that I switched direction of the coordinate system (in y-direction). In
plotData():My calls to
set_xlimandset_ylimdid exactly what they were supposed to, it was just that with the limits I set the data was no longer visible in these plots (since I switched the sign of the y-axis on the data but not on the limits).