Is it possible to plot the ticks but not the axes?

3 views (last 30 days)
Is it possible to plot the small tics marks perpendicular to the axes, but not the x and y-axes?
  1 Comment
Mr M.
Mr M. on 7 Jul 2015
Its very strange. Because it is possible to draw the axes without tics :) And how to change the visibility of the axes?

Sign in to comment.

Answers (1)

Thorsten
Thorsten on 7 Jul 2015
Edited: Thorsten on 8 Jul 2015
No, but you can draw a white line on top of the axes.
Or you can use my function onlyticks
function onlyticks
%ONLYTICKS Plot only the ticks of the axis.
%
% ONLYTICKS Plot only the ticks of the axis.
% Ticks drawn by ONLYTICKS are unaffected by subsequent calls of
% BOX OFF or AXIS OFF.
%
% Thorsten.Hansen@psychol.uni-giessen.de 2015-07-08
plotsize = min([diff(xlim) diff(ylim)]);
xticklength = 0.015*plotsize;
yticklength = 0.01*plotsize;
% xticks
xpos1 = get(gca, 'XTick');
xpos = flatten([xpos1; xpos1; nan(1,numel(xpos1))])';
ylims = ylim;
ypos = ylims(1) + [0 xticklength];
ypos = repmat([ypos nan(1,1)], [1 numel(xpos1)]);
if strcmp(get(gca, 'Box'), 'on')
% add ticks on top of plot
xpos = [xpos xpos];
ypos = [ypos ypos + diff(ylims) - xticklength];
end
line(xpos(1:end-1), ypos(1:end-1), 'Color', get(gca, 'XColor'))
% yticks
ypos1 = get(gca, 'YTick');
ypos = flatten([ypos1; ypos1; nan(1,numel(ypos1))])';
xlims = xlim;
xpos = xlims(1) + [0 yticklength];
xpos = repmat([xpos nan(1,1)], [1 numel(ypos1)]);
if strcmp(get(gca, 'Box'), 'on')
% add ticks on top of plot
ypos = [ypos ypos];
xpos = [xpos xpos + diff(xlims) - yticklength];
end
line(xpos(1:end-1), ypos(1:end-1), 'Color', get(gca, 'YColor'))
axis off

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!