Why is the text function not showing the text for this figure?

22 Ansichten (letzte 30 Tage)
Here is my sample code:
colormap parula
cm = colormap;
latZone1 = [25, 25, 50, 50, 25];
lonZone1 = [-105, -125, -125, -105, -105];
zone1Poly = geoshape(latZone1, lonZone1);
zone1Poly.Geometry = 'polygon';
zone1Color = cm(33,:);
states = geoshape(shaperead('usastatehi', 'UseGeoCoords', true));
figure('Visible','on');
hold on
ax = usamap([25 50],[-125 -65]);
geoshow(states,'FaceColor', 'w')
geoshow(zone1Poly, 'LineWidth', 1,'FaceColor',zone1Color,'FaceAlpha',.5)
text(37.5,-115,'Zone 1')
When I run it, the text does not show. Do I need to get the handle and change the font size? I figured it would scale to the figure but I could be wrong. Any help is greatly appreciated!
  1 Kommentar
dpb
dpb am 29 Sep. 2016
I don't have and have never used the mapping toolbox so I don't know but I'm guessing text isn't overloaded and so you've given the coordinates as latitude/longitude as you do with mapping functions but the actual axes are oriented t'other way 'round--if that's so, then
text(-115,37.5,'Zone 1')
should fix your problem. Mayhaps there's a function for the purpose specific to the mapping toolbox???

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Massimo Zanetti
Massimo Zanetti am 29 Sep. 2016
The problem is that the coordinates you are using to put text do not correspond to the ones in the axes. If you try using normalized coordinates, it will work:
Use
text(.5,.5,'Zone 1','FontSize',30,'Units','normalized');
Instad of
text(37.5,-115,'Zone 1');

Weitere Antworten (1)

youngjae jang
youngjae jang am 2 Okt. 2021

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by