Specifying color data for patchm or patchesm
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 27 Sep 2017
Réponse apportée : MathWorks Support Team
le 29 Sep 2017
How do I specify different colors for different faces of my patch on map axes, using "patchm" or "patchesm"? I want to create a patch object that has multiple faces, and I want to color the faces differently.
When I attempt to pass a vector of color values, which has the same length as the number of faces, as the "cdata" parameter to either "patchm" or "patchesm" I get the error "Color value must be a 3 element numeric vector". My code is as follows:
>> load coastlines
>> axesm sinusoid;
>> framem
>> numOfFaces = 243;
>> colormap(jet(numOfFaces))
>> caxis([1 numOfFaces])
>> zVal = 0;
>> colorData = (1:numOfFaces)';
>> h = patchm(coastlat, coastlon, zVal, colorData, 'FaceColor', 'flat');
Similarly, "patchesm" gives the same error if I pass a vector as the "cdata" parameter.
Réponse acceptée
MathWorks Support Team
le 20 Nov 2018
The "cdata" parameter of both the "patchm" and "patchesm" constructor expects to receive a singular color value, specified as either a color name (e.g. 'r' or 'red') or an RGB triplet (e.g. [1 0 0]). It will not take in a vector of color values that correspond to the different face colors.
Unlike "patch", providing a scalar value for "cdata" in the constructor for "patchm" or "patchesm" does not use the "CDataMapping" property to map into the colormap.
However, since "patchm" supports nearly all the properties that are supported by the "patch" function, we can color the faces by passing property name/property value pairs to the "patchm" function, as follows:
>> patchm(latData, lonData, 'FaceVertexCData', faceColors, 'FaceColor', 'flat')
This command will create a single patch with multiple faces, with the face colors specified by the array "faceColors". Specifics on the allowed formats of the array "faceColors" can be found on the Patch Properties documentation page, under the property "FaceVertexCData", linked here:
Since "patchesm" returns an array containing a separate patch object for each face, it is necessary to set the color of each of the patch objects individually to accomplish the same behavior.
For more information about these properties, please refer to the above link.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Polygons dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!