Error in the simultaneous use of contourf and geolimits
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have a problem with my code. I am trying to combine two kinds of maps. the first one is the contour map, and the ather one is the geomap with the geolimit command.
My code is above:
figure(5)
S=shaperead('C:\Users\hp\Desktop\MY_MAP.shp');
lat_grid2=ltln(:,1);
lon_grid2=ltln(:, 2);
Z=ltln(:, 3);
[lon_si, lat_si] = meshgrid(...
linspace(min(lon_grid2),max(lon_grid2)),...
linspace(min(lat_grid2),max(lat_grid2)));
m_alli = griddata(lon_grid2,lat_grid2,Z, lon_rmsi,lat_rmsi,'natural');
contourf(lon_si,lat_si,m_alli,15,'ShowText','on');
mapshow(S,'Color', 'black','LineWidth',2)
set(gca,'ColorScale','log');
colormap(flipud(jet(5)));
colorbar
geolimits([min(lon_grid2) max(lon_grid2)], [min(lat_grid2) max(lat_grid2)])
but command window shows me the error:
Error using geolimits (line 66)
Unable to use geolimits. Current axes or chart is not geographic.
Could you please help me?
채택된 답변
Walter Roberson
2022년 8월 1일
use contourm() with 'Fill' option perhaps
contourf() is just contour() with fill, not a different computation
댓글 수: 12
Thank you but the point is that I would like to fill my contours and simulatneously to have geolimits.
Is there any way to make it?
If not is there any way to "add' the scaleruler (horizontal scale) in the map?
I will not currently say that there is no way to do it, but I would point out that you have not used any geoaxes drawing routines, so using geolimits is inappropriate. For example you do not even use geoshow, so you are working in an unprojected plain axes.
Walter Roberson
2022년 8월 1일
편집: Walter Roberson
2022년 8월 1일
call contour() and store the first output . It will be a contour matrix, not a graphics object .
Look in the File Exchange for the contribution that converts contour matrix to struct array.
Loop over the struct members. Use the stored coordinates to construct https://www.mathworks.com/help/map/ref/geopolyshape.html
Now you can geoshow() the geopolyshape vector to achieve the effect of filled contours .
You can follow by geoshow the shape information that you read .
I add in my code the following lines :
scaleruler on
setm(handlem("scaleruler"), ...
"XLoc",21,"YLoc",36.5, ...
"MajorTick",0:200:600, ...
"FontSize",8)
setm(handlem('scaleruler'),'RulerStyle','patches')
but command window shows me:
Error using gcm (line 25)
Not a map axes.
Error in getm (line 80)
gcm(maphndl);
Error in scaleruler>scalerulerOn (line 89)
if strcmp(getm(ax,'mapprojection'),'globe')
Error in scaleruler (line 57)
h = scalerulerOn(s,gca);
But as I mentioned earlier you can contourm with 'fill' turned on, and that would be a map axes.
Ok , It works thank you.
figure(5)
[lon_si, lat_si] = meshgrid(...
linspace(min(lon_grid2),max(lon_grid2)),...
linspace(min(lat_grid2),max(lat_grid2)));
zi = griddata(lon_grid2,lat_grid2,Msyn,lon_si,lat_si,'natural');
contourm(lat_si,lon_si,zi,12,'ShowText','on','fill','on');
hold on
geoshow(S,'Color', 'black','LineWidth',2)
set(gca,'ColorScale','log');
colorbar;
xlim([min(lon_grid2),max(lon_grid2)]);
ylim([min(lat_grid2),max(lat_grid2)]);
One last question. How could I add a scale map in my map?
Excuse me but I can not solve this problem..
How could I add a scale map in my map?
I tried to add "geobasemap" command and command line shows me the following message:
Error using geobasemap>parseInputs (line 78)
Unable to use geobasemap. Current axes or chart is not geographic.
Error in geobasemap (line 30)
[gx, basemap, usingBasemapSyntax] = parseInputs(varargin);
Could you please help me?
Sorry, I went back and checked, and there is no way to do what you want. The only kind of filled polygons supported by geographic axes is bubbles.
ok.. One last question.. Is there any way to add a scalebar (scaleruler) in the part of the map ? (like in the attached figure)

Could you please help me?
if you are using contourm then you can use scaleruler()
I am using these commands:
figure(6)
S=shaperead('C:\Users\hp\Desktop\MY_MAP.shp');
[loni, lati] = meshgrid(...
linspace(min(lon2),max(lon2)),...
linspace(min(lat2),max(lat2)));
mw_alli = griddata(lon2,lat2,Z,loni,lati,'natural');
[c,h]=contourm(lat_rmsi,lon_rmsi,mw_alli,12,'ShowText','on','fill','on');
hold on
geoshow(S,'Color', 'black','LineWidth',2)
colorbar;
scaleruler on
setm(handlem("scaleruler"), ...
"XLoc",21,"YLoc",36.5, ...
"MajorTick",0:200:600, ...
"FontSize",8)
setm(handlem('scaleruler'),'RulerStyle','patches')
But command window shows me:
Error using gcm (line 25)
Not a map axes.
Error in getm (line 80)
gcm(maphndl);
Error in scaleruler>scalerulerOn (line 89)
if strcmp(getm(ax,'mapprojection'),'globe')
Error in scaleruler (line 57)
h = scalerulerOn(s,gca);
which is the mistake? How could I modify my code in order to work?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Create Plots on Maps에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
