How to add (minor) ticks on loglog plot?

조회 수: 39 (최근 30일)
Elin
Elin 2014년 10월 2일
댓글: Star Strider 2021년 4월 29일
I plot my data in log scale and some of the graphs don't have any ticks at all. I have tried to add ticks on the y-axis on the loglog plots, but the axis scale then changes back from log-scale to normal scale.
These are some of the different settings that I have tried:
1) set a fixed tick scale:
set(gca, 'YTick', [10.^0 10^0.4 10^0.8 10^1 10^1.3 ])
2) set a tick range:
set(gca, 'YTick', [0.001: 4 : 13])
3) Turn the minor tick function on:
set(gca,'YMinorTick','on')
So, how do I add ticks and keep the log scale? I work in Matlab 2012a, Mac OSX
/ Elin

채택된 답변

dpb
dpb 2014년 10월 2일
  댓글 수: 3
Ben E
Ben E 2021년 4월 28일
Broken link!
Star Strider
Star Strider 2021년 4월 29일
The Newsreader has been gone for several years. You might be able to find it archived on Google Groups or something similar if you enjioy spelunking Usenet archives.

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

추가 답변 (2개)

Star Strider
Star Strider 2014년 10월 2일
편집: Star Strider 2014년 10월 2일
This works with this code. You may have to experiment with it with your plot:
x = logspace(-1,1.5);
y = exp(x);
figure(1) % Default Behaviour
loglog(x,y,'-s');
grid on
figure(2) % Selected Behaviour
loglog(x,y,'-s');
grid on
yt = get(gca, 'YTick');
ytkvct = 10.^linspace(1, 10*size(yt,2), 10*size(yt,2));
set(gca, 'YTick', ytkvct);
set(gca, 'YMinorTick','on', 'YMinorGrid','on')
produces this plot:

Harshad Deshmane
Harshad Deshmane 2014년 10월 2일
I created a sample "loglog" plot and tried changing the ticks and turning on minor ticks on the y-axis. I followed the approach that you mentioned. But the axis scale did not change from log to linear for me. (I used MATLAB R2012a on Mac OSX 10.9.2.)
One thing you can try is to click on the 'Show Plot Tools and Dock Figure' button on the figure window. This will open a UI which allows you to make any changes to your figure/axes. You can click inside the axes and set the Y scale, change the tick locations and labels, and turn on/off minor ticks.
  댓글 수: 3
Elin
Elin 2014년 10월 3일
Yes thanks, that's the issue. Now that you mention it, I see that it's not the scale that changes back to normal scale but the formatting of the labels
dpb
dpb 2014년 10월 3일
Ayup...which is why the use of text is the way instead of adding more major ticks if want to keep the same exponential formatting as the default.
Now again, here's one of the unsolved mysteries/frustrations with handle graphics--since they go to the trouble to initially write the exponential form, why doesn't set for the case of log scale have the internal smarts to at least write other integer-valued tick values in the same format (or better yet have a formatting property that gives the user the flexibility to specify the format desired)?
As is, as is so often the case, the actual look of graphics just isn't as professional as one would like for presentation purposes at least without the user taking a lot of time and effort to fix up such faux pas. One that just bugs me no end that's trivial to fix but has been around "since forever" is the missing decimal ".0" at the origin and upper limits in the default axes -- it's simply just tacky as is.

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

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by