How to transform a Group object to a Contour object?

I am using the "hatchfill2" function to display regions of statistical significance on a map. The base map is created using the "pcolorm" function, while the contours for hatching are created with the "contourm" function. The hatching function doesn't work as the "contourm" function returns a "Group" object, unlike the standard "contour" function (which returns a "Contour" object). So I want to either return a contour object by invoking the contourm function, or transform the Group object into a contour object. I am using R2020b version of MATLAB. Any tips will be highly appreciated! Thank you in advance !

 Réponse acceptée

Walter Roberson
Walter Roberson le 26 Fév 2023

0 votes

The problem is not exactly that contourm() returns a hggroup . hatchfill2() processes hggroup without difficulty, recursing to handle all of its Children.
The problem is that once the internal functions get down to an individual graphics object, the graphics object must be area or bar or contour or histogram or patch or surface but that the hggroup children created by contourm() are Line objects.
The internal functions extract or convert the data from those kinds of objects into Face and Vertex data. In principle the function could be extended to also handle Line objects .
There is the additional twist that the Line objects created by contourm() have NaN in them. That is, contourm() generates one Line object for each contour level, and in order to deal with the fact that there might be several different regions with the same contour level, the Line objects created are of the form [xblock1 nan xblock2 nan xblock3 ... nan] where each of those blocks is a list of x coordinates with the first and last coordinate typically the same (so that the contour closes)... but if the contour runs off the edge of the map, then the coordinates would not close. Which would have to be detected.
You could write a function yourself that broke apart the hggroup Line objects and created a bunch of Face and Vertex arrays from the XData and YData. If you wanted to process the result through hatchfill2() you would need to create true patch or surface objects -- the hatchfill2 code uses ishghandle(A, 'patch') and so on. Which is not a documented syntax, but anyhow the point is that just creating a struct() with all of the appropriate fields would not pass that particular test...

1 commentaire

Thank you so much for the explanation, Walter. I'll work on your suggestion and update this thread once I manage.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by