plot a line of different colors on a map with patch (m_patch m_map)
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi
I am trying to draw a line with different colors in a map. I succed making it in a non-map figure following this answer (https://www.mathworks.com/matlabcentral/answers/21382-plot-different-color), but when I try to include it in a map using the m_map package it doesn't work (neither after a simple pcolor figure with ETOPO). There is no error warning in the command window. No matters if I use m_patch or patch. I tried on Windowns and with Linux based computers.
Here is my code:
xlon=210:1:260;
y=rand(51,1);
ylat=sin(30)*y+45; ylat=ylat';
z=rand(51,1); z=z';
%
figure(1)
patch([xlon nan],[ylat nan],[z nan],[z nan], 'edgecolor', 'interp');
colorbar;colormap(jet);
%%
regionlatlon=[30, 60, 210,250]; % limites lat lon para mapa
lon=210:2:260;
lat=30:2:60;
%
figure (2)
m_proj('Miller','lat',regionlatlon(1:2),'lon',regionlatlon(3:4));%
m_grid; hold on;
[lon,lat] = meshgrid(lon,lat);
m_coast('color', [.1 .1 .1]);
m_patch([xlon nan],[ylat nan],[z nan],[z nan], 'edgecolor', 'interp');
colorbar; colormap(jet)
댓글 수: 0
답변 (1개)
Sachin Lodhi
2023년 11월 10일
Hi Jose,
Based on my understanding, it seems that you want to plot a line of different colors on a map with ‘m_patch’ function.
The ‘m_patch’ function in the ‘m_map’ package does not support the ‘edgecolor’ property with ‘interp’ value. It is designed to fill polygons in map coordinates, and does not support the same set of properties as the built-in ‘patch’ function.
If you want to draw a line with different colors on a map, you can use the ‘m_line’ function with the ‘Color’ property set to a colormap. However, this will color the entire line with the same color.
One workaround is to break the line into small segments, and draw each segment with a different color. Here is an example:
% Draw line in segments, each with a different color
for i = 1:length(xlon)-1
m_line([xlon(i) xlon(i+1)], [ylat(i) ylat(i+1)], 'Color', cmap(z_norm(i),:), 'LineWidth', 2);
end
I hope this helps.
Best Regards,
Sachin
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!