filled contour no longer creates patch children ... what is equivalent for setting the ZData?

I have a method for plotting the coastlines under or on top of some 3D scatter data, depending on whether the z levels are depth, pressure, or height. It used to grab the children of the contourf object and set the ZData property - independent of the actual values of the contourf object. This worked great until 2014b (?) and certainly doesn't work for 2015b ... I have not tried all versions. Attached is a short example - if you run it with 2014a or before, it works fine. 2015b fails - there are no patch objects generated by the contourf.
I have tried shifting the contourf z data to center the contour at the desired level, that did not work.

 Accepted Answer

There is no equivalent mechanism now :( Parent a contourf() against an hgtransform that uses a translation along the Z axis of the desired Z value. You might need to do that for each distinct Z value.

4 Comments

That would look something like this.
Where you're creating the contour, you need to parent it to a hgtransform like this:
htrans = hgtransform;
htrans.Matrix = makehgtform('translate',[0 0 zlevel]);
[c,h] = contourf(lons,lats,topo,[0.0 0.0],'k-', ...
'Parent',htrans);
Then you can delete all of the code that's finding the patches and setting their ZData.
Unfortunately, when I tried this, I hit a few other issues. The first is that sometimes the ZLim you're getting from the axis command isn't a good choice because it can change later when the colorbar is added.
You weren't noticing that in earlier versions of MATLAB because of a clipping bug that would let the contour get drawn even if it was outside the ZLim. That clipping bug was fixed in R2014b. The simplest way to get a ZLim value that isn't going to change is to use
axis tight
After those two changes, I get this:
Thanks Walter, I appreciate your fast response.
Fair enough. (for the interested) The syntax that worked for me is:
<create your scatterplot>
[~,h] = contourf(lons,lats,topo,[0.0 0.0],'k-');
t1 = hgtransform('Parent',gca);
set(h,'Parent',t1);
m = makehgtform('translate',[0 0 zlevel]);
set(t1,'Matrix',m)
this does indeed translate the filled contours to whatever zlevel you specify. I am now onto trying to set the color for that (single) filled contour to something that is not actually in the colorbar (a light gray, for example). I think I will abandon the translucency, etc. that I could specify for the patch objects.
I have attached a more mature version that additionally sets the colorbar levels to the level of the data values, not the range of the z limits (as in my first example).
Thanks to Mike as well. I was so preoccupied implementing and then tweaking my example script that I did not read Mike's post in a timely fashion. Mike - for the record - I just pared down a much more complicated example for the purposes of clarity. My full-blown function does handle the data limits and clipping appropriately. Thanks.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!