Specifying color data for patchm or patchesm
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 27 de Sept. de 2017
Respondida: MathWorks Support Team
el 29 de Sept. de 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.
Respuesta aceptada
MathWorks Support Team
el 20 de Nov. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!