Add a label to a minor tick, in an inset plot
Afficher commentaires plus anciens
How to add a label of one minor tick (in the x-axis) of an inset plot?
% create a plot
x1 = linspace(0,1000);
y1 = sin(2*pi*x1);
plot(x1,y1)
set(gca,'Fontsize',20,'FontWeight','normal','LineWidth',1);
% create the inset plot
ax2 = axes('Position',[.45 .45 .4 .4]);
box on
plot(x1,y1) % <-- inset plot
set(ax2,'XScale','log') % <-- set log-scale for the x-axis of the inset plot
set(ax2,'Fontsize',20,'FontWeight','normal','LineWidth',1);
ax2.TickLength = [0.04 0];
% Set the axes limits
xlim([0 60])
ylim([0 Inf])
% Display the values/positions of both the major and minor ticks
drawnow
ax2_mtv = ax2.XAxis.MinorTickValues % <-- get the values/positions of the minor ticks in the inset plot
ax2.XTick % <-- get the values/positions of the the major ticks in the inset plot
My desired output is to add the label of the highlighted (in yellow) minor tick "ax2_mtv(1)", i.e."15", as follows, and without getting extra minot ticks (please see my comment below):

3 commentaires
Hi @Sim
% Create a main plot
x1 = linspace(0, 1000);
y1 = sin(2*pi*x1);
plot(x1, y1)
set(gca, 'FontSize', 20, 'FontWeight', 'normal', 'LineWidth', 1);
% Create the inset plot
ax2 = axes('Position', [.45 .45 .4 .4]);
box on
plot(x1, y1) % Inset plot
set(ax2, 'XScale', 'log') % Set log-scale for the x-axis of the inset plot
set(ax2, 'FontSize', 20, 'FontWeight', 'normal', 'LineWidth', 1);
ax2.TickLength = [0.04 0];
% Set the axes limits
xlim([0 60])
ylim([0 Inf])
% Display the values/positions of both the major and minor ticks
drawnow
ax2_mtv = ax2.XAxis.MinorTickValues; % Get the values/positions of the minor ticks in the inset plot
minor_tick_position = ax2_mtv(1); % This is the position '15' you want to label
% Add a text label "x=fifteen" at the position of the minor tick
text(minor_tick_position, 0, 'x=fifteen', 'FontSize', 14, 'VerticalAlignment', 'top', ...
'HorizontalAlignment', 'center', 'Parent', ax2);
Sim
le 3 Sep 2024
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Axis Labels dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




