matlabmatlab-figure

Show only tick labels and hide tick marks: MATLAB 2024b


How do I hide the tick marks, but keep the tick labels on both y axis of a graph?

My formatting for the axis is

yyaxis left;
b = bar(data(2:end-1,:)', "stacked");
xticklabels(data(1, :));
ax1 = gca;
ax1.YGrid = "on";
ax1.YLim = [0, 1000];
...

yyaxis right;
l = plot(data(end, :), 'k');
l.LineWidth = 2;
ax2 = gca;
ax2.YLim = [0,30];

box off;

The result:

Current Image

The desired format:


Solution

  • The ticklengths are both in your ax1 (also both in your ax2 which is the same as your ax1):

    data = [2000 2010 2020;
    300 400 500;
    50 40 30;
    10 15 20];
    yyaxis left;
    b = bar(data(2:end-1,:)', "stacked");
    colororder('default')
    xticklabels(data(1, :));
    ax1 = gca;
    ax1.YGrid = "on";
    yyaxis right;
    l = plot(data(end, :), 'k');
    l.LineWidth = 2;
    box off
    
    ax1.YAxis(1).Limits = [0 1000];
    ax1.YAxis(2).Limits = [0 30];
    ax1.YAxis(1).TickLength = [0 0];
    ax1.YAxis(2).TickLength = [0 0];
    

    enter image description here