How to change the Xtick direction of ONLY one of the two (top or bottom) X-axis lines ?

6 Ansichten (letzte 30 Tage)
The following example shows two thick X-axis lines, one at the bottom and one at the top.
I would like to set the "TickDirection" as "Out" for the bottom X-axis line, and still keep the "TickDirection" as "In" for the top X-axis line.
How to do it?
% my plot
% properties
ax = gca;
xax = ax.XAxis;
set(xax,'TickLength',[0.03, 0.01])

Akzeptierte Antwort

dpb am 16 Mär. 2023
% my plot
% properties
hAx1 = gca;
hold on
And you see you still have the ticks on the opposite side of each the X- and Y- axes. HG2 (Handle Graphics 2) doesn't have the granularity to control the tick marks individually; either they show if 'Box' is 'on' or they don't if 'off'.
You would have to draw either ticks or the outer box manually to create the effect you're after, unfortunately.
  5 Kommentare
Sim am 18 Mär. 2023
Bearbeitet: Sim am 18 Mär. 2023
I agree 100% about everything you wrote!! And it is exactly what I think for years... often, to adjust the most trivial things in a plot - those things that one expects to be very easy to handle -, I spend a considerable time and they are not easily accessible. This means that we need to dig deep in obscure half-hidden and undocumented/uncommented properties... Sometimes I wonder if Matlab competitors, such as Python or R, have similar intricate properties and features related to graphical adjustments... :-)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Sim am 18 Mär. 2023
Bearbeitet: Sim am 18 Mär. 2023
This is just a variation of the @dpb solution, that I have used in one case.
Please note that I write it here - instead of adding it in a comment - as an alternative solution.
Obviously, I will not accept it since it is a rearrangement of the @dpb solution.
% my plot
% define the first axes (from the current axes) and set some properties
ax(1) = gca;
set(ax(1),'Fontsize',15,'FontWeight','Bold','LineWidth',2, 'box','on');
% define the second axes and set some properties
ax(2) = axes('Position',ax(1).Position,'Color','none');
ax(2).XAxisLocation = 'bottom';
ax(2).YAxis.Visible = 'off';
ax(2).XAxis.TickDirection = 'out';
ax(2).XTickLabels = [];
ax(2).XTick = [0 ax(1).XTick]; % <-- Xticks positions in the 2nd axes as in the 1st axes
% link the first axes with the second axes
% other properties
ax(1).XRuler.TickLabelGapOffset = 20; % <-- adjust ticklabels away from axes
ax(2).XAxis.TickLength=[0.05 0]; % <-- change the length of the tick marks
set(ax(2),'Fontsize',15,'FontWeight','Bold','LineWidth',2, 'box','off');

Community Treasure Hunt

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

Start Hunting!

Translated by