I would like to know how to make sure the latitude labels have decimals in them.

조회 수: 3 (최근 30일)
Cg Gc
Cg Gc 2024년 6월 25일
편집: dpb 2024년 6월 26일
I have this code creating a map of a small portion of Antarctica. I have the latitude lines appearing ever half of a degree, but the labels still show single degrees. Is it possible to have the labels have decimals?
Also is it possible to have the longitude lines appear with labels on the map instead of on the edge?
The base of the map is Bedmap.
figure('Color','w')%Colors the figure white .
set(gca, 'Color', 'none');
mapzoom(-81.6, -148.8);%'size',[100 100]);
framem on ; gridm on ; mlabel on ; plabel on ;
bedmap2('gl','color','k','linewidth',1)
bedmap2('coast')
setm(gca,'plinelocation',.5,'plabellocation',0.5 ,...
'labelrotation','on');
hold on;
  댓글 수: 3
dpb
dpb 2024년 6월 25일
You'll need to submit a minimum working example -- but in general the answer to the question would be whatever is the equivalen with an axesm axis object as the following for a regular axis.
hAx=gca;
hAx.XAxis.TickLabelFormat='%.1f';
The default axis is a NumericRuler; the map axis is undoubtedly some other object and so may have different properties, but one of the will be the format string that is undoubtedly set to '%g' by default which cause the butt-ugly display of mixing plain integer and fixed format strings together. This behavior has irritated me no end since the initial introduction of MATLAB.

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2024년 6월 26일
편집: dpb 2024년 6월 26일
Anywhere after the axis is created...for ease of coding, save the handle to the axis object when creating it.
You haven't provided any code that can be run without other pieces/things you haven't supplied so all can do is talk generalities...I don't have the Mapping TB so can't play except here.
But, the error above says it expected an axesm axis so let's see what that would give us...
axesm;
hAxm=gca;
"Code Run Timed Out
Your code took longer than 235 seconds to run. Simplify code and then run again."
Well, not sure how one would simplify a single function call with zero arguments; looks as though this platform won't let is illustrate with actual code...
But, it appears from the doc on <axesm Properties> the axesm object doesn't do the tick labels the same way by specifying a format string as above, but by a precison, _
MLabelRound — Specify significant digits for meridian labels
0 (default) | integer scalar
Specify significant digits for meridian labels — Specifies to which power of ten the displayed labels are rounded. For example, if MLabelRound is -1, labels are displayed down to the tenths. The default value of MLabelRound is 0; that is, displayed labels have no decimal places, being rounded to the ones column (100).
There's a second,
PLabelRound — Specify significant digits for parallel labels
So, the above would instead be something like
axesm('MLabelRound',-1,'PLabelRound',-1);
to create the axes and set the precison to tenths on creation.
It also appears there is a special set of set/get functions specifically, setm to make changes after the fact.
The documentation doesn't show it returning a handle to the object; the examples only show using setm/getm and not referencing the structure properties with the named doc convention, but one would presume this would also be possible. But, I can't test...
  댓글 수: 1
Cg Gc
Cg Gc 2024년 6월 26일
I stumbled upon the 'MLabelRound' as well. It is the same for 'PLabelRound'. For those that are using this in the future, MLabel is the meridian labels, these are your lines of longitude. PLabel is for the parrallel lines or lines of longitude.
-1 means it will round to the tenths. -2 to the hundredths and so on.
Make sure you put both in ' ', but leave the numbers not in quotes.
'plinelocation' or 'mlinelocation' is not the location of the labels, but rather the number of these lines you want visible. If you put 1, then they will be every 1 degree. If you put 5, they will be every 5 degrees. If you want half degrees, then put 0.5 or .5.
I am still working on the label placement location. I honestly gave up and just put in the labels with textboxes because it was faster than trying to figure out how to move the labels off of the default locations.

댓글을 달려면 로그인하십시오.

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by