Search code examples
matlabplotaxes

Determining the region with data in a pcolor plot


I have a plot showing a map in a pcolor plot in Matlab R2012a/R2014a (=using the old graphic system) and want to implement panning and zooming.

Because the dataset is quite large (and needs to be interpolated from vector data), I would prefer not to plot the whole region at high resolution, but only a small fraction of it and then pan around. But I want to redo the plot once I pan out of this subregion, such that it contains the next subregion.

Is there some way to get the limits of the region with data in an axes object the same way I can the limits of the currently displayed region via get(myAxes, '[XY]lim')? This way I could replot only if necessary.

A workaround would be to store the limits inside a handles structure everytime I execute pcolor, but I wonder if there is something built ín for this case.


Solution

  • I found a solution.

    The region is not stored in the axes object itself, but in one of its children (the one containing the actual plot). It is if type surface for pcolor plots and hggroup for contour plots. So you can find it via

    childHandle = plotfindall(myAxes, 'Type', 'surface')
    

    This object contains all the data used for plotting in its properties XData, YData and ZData. The largest x value with data and already plotted (but maybe not in the visible range) can be determined via

    xd = get(childHandle, 'XData');
    maximumXWithData = max(xd(:));