Wrong patch using the Faces and Vertices properties when projected on map (patchm)
Afficher commentaires plus anciens
I am trying to color lines by a specific value using patch and patchm where I use vertices and faces (my faces are actually only lines with a start and end point). The lines connect some station pairs, i.e. station 1 with station 2, station 1 with station 3, etc. Each station pair is defined by latitude and longitude and stored in the variable verts.
verts(1:10,:)
ans =
63.4946 9.7362
62.7815 7.1518
63.4946 9.7362
62.7836 8.8780
63.4946 9.7362
62.7205 10.0433
63.4946 9.7362
62.5622 11.5530
63.4946 9.7362
62.1345 5.9689
The specific values for the station pairs are stored in the variable cohmap.
cohmap(1:10)
ans =
0.9318
0.9318
1.0166
1.0166
1.0346
1.0346
1.1186
1.1186
1.0251
1.0251
When I use a simple x,y plot using patch everything works out correctly. The correct station pairs are connected and colored by their correct values.
fac=[1:2:10; 2:2:10]'; p=patch('Faces',fac,'Vertices',verts,'FaceColor','none','EdgeColor','flat', 'LineWidth',1);
set(gca,'CLim',[0 1]);
colormap(jet);
set(p,'FaceColor','flat','FaceVertexCData',cohmap,'CDataMapping','scaled')
colorbar
for snm = 1:length(stlas)
plot(stlos(snm), stlas(snm), 'k^', 'MarkerFaceColor', 'k');
end

However, when I try to project the patch to a map using patchm I get this result:

ax = worldmap([57 64], [4 14]);
set(ax, 'Visible', 'on', 'FontSize',8)
setm(gca,'FLineWidth',1, 'fontsize', 4, 'LabelFormat', 'none', 'MLineLocation', 3, 'PLineLocation', 3, 'MLabelLocation', [6 9 12 15], 'PLabelLocation', [57 60 63], 'MLabelRound', 0, 'PLabelRound', 0);
p = patchm(verts(:, 1), verts(:, 2), 'Faces', fac, 'FaceColor','none','EdgeColor','flat', 'LineWidth',2, 'FaceVertexCData',cohmap,'CDataMapping','scaled');
set(gca,'CLim',[0 1]);
colormap(jet);
colorbar
for snm = 1:length(stlas)
plotm(stlas(snm), stlos(snm), 'k^', 'MarkerFaceColor', 'k');
end
borderN = shaperead('/path/NOR_adm0.shp', 'UseGeoCoords', true);
borderS = shaperead('/path/SWE_adm0.shp', 'UseGeoCoords', true);
geoshow(borderN.Lat, borderN.Lon, 'Color', [0.66, 0.66, 0.66],'linewidth', 0.5)
geoshow(borderS.Lat, borderS.Lon, 'Color', [0.66, 0.66, 0.66],'linewidth', 0.5)
Obviously, using patchm wrong station pairs are used. What is going wrong here? Why I get this using patchm?
Réponse acceptée
Plus de réponses (1)
Chad Greene
le 31 Mar 2015
I've had similar problems with patchm before. I'm not sure why it helped in my particular case, but the fix I found was to flip the arrays of lats and lons, like this:
p = patchm(flipud(verts(:, 1)),flipud(verts(:, 2)),...
No guarantee that it'll work, but give it might be worth a shot.
1 commentaire
Colibri
le 1 Avr 2015
Catégories
En savoir plus sur Polygons dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!