MATLAB: Do I not get any YTick marks on the semilogy PLOTYY axis in MATLAB 7.5 (R2007b)

axesdwhhgwaitgraphMATLABplotplotyysemilogarithmicsemilogysety axisylim;ytickyticklabel

I am using the PLOTYY function to create a 2-D plot with y-axes on both left and right side. In the PLOTYY function I specify ‘semilogy’ as an argument to produce the graph with logarithmic scales for the y-axis. But I do not get any YTick or YTickLabels on the y-axis, only the YLim is displayed. Furthermore, the YLim in not the same as using the SEMILOGY function to produce semilogarithmic plots. This is an example that describes the issue:
a=5:50:500;
b=1000:1000:10000;
c=1:1:10;
figure
plotyy(c,a,c,b,'semilogy','semilogy');

Best Answer

  • In this particular case, PLOYTYY is showing the correct behavior. PLOTYY maintains two constraints:
    1) That the number of ticks on the y axes are the same (so that y-ticks exist at the grid lines should the axes grid be enabled), and
    2) In log spaces, that the ticks occur at powers of ten. Often, the only y-ticks that satisfies both constraints are at the upper and lower limits of the y-axes.
    To work around this issue, set the YLim and YTick marks manually:
    a=5:50:500;
    b=1000:1000:10000;
    c=1:1:10;
    figure
    plotyy(c,a,c,b,'semilogy','semilogy');
    ha=findobj(gcf,'type','axes');
    set(ha(1),'ylim',[10^3 10^4],'ytick',[10^3 10^4])
    set(ha(2),'ylim',[10^0 10^3],'ytick',[10^0 10^1 10^2 10^3])