Plot and zoom in - axis labels doesnt work?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am using nxt code to make my plot:
figure;
set(0,'defaulttextinterpreter','latex');
set(0, 'defaultAxesTickLabelInterpreter','latex');
set(0, 'defaultLegendInterpreter','latex');
set(gca,'FontSize',16);
xlabel('\textit{z}','FontSize',16,'Interpreter', 'LaTeX');
xlabh = get(gca,'xlabel');
set(xlabh, 'HorizontalAlignment','center');
xpos = get( xlabh , 'position' );
ylabel('\textit{p}','FontSize',16,'Interpreter', 'LaTeX');
ylabh = get(gca,'ylabel');
ypos = get( ylabh , 'position' );
set(ylabh, 'VerticalAlignment','middle', 'Rotation',0);
set(gca,'Units','normalized');
set(gca,'box','on');
set(gcf, 'PaperUnits', 'centimeters', 'PaperSize', [7, 7]);
xpos1 = [0.1 5 0];
ypos1 = [-0.08 4.8 0];
set( xlabh , 'position' , xpos1 );
set( ylabh , 'position' , ypos1 );
txtRee = ['$Re_e=\,\,$', num2str(Ree)];
txteps = ['$\varepsilon=\,\,$', num2str(eps)];
txtRi = ['$R_i=\,\,$', num2str(ri)];
plot(z, p3uk, 'k:', 'LineWidth', 2);
hold on;
plot(z, pns1, 'k--', 'LineWidth', 1.5);
hold on;
plot(z, pns2, 'k-.', 'LineWidth', 1.5);
txt = {txtRee, txteps, txtRi};
text(0.4, 5.2, txt, 'FontSize', 16, 'Interpreter', 'LaTeX');
legend({'(?)', '$\mathcal{O}(Kn)$ [3]', '$\mathcal{O}(Kn^2)$ [3]'},'FontSize',16,'Interpreter', 'latex')
legend boxon;
% zoom
axes('position',[0.2 0.2 0.3 0.25]); % four-element vector of the form [left bottom width height]
box on; % put box around new pair of axes
indexOfInterest3 = (z < 0.51) & (z > 0.5); % range of t near perturbation
plot(z(indexOfInterest3),pns1(indexOfInterest3),'k--', 'LineWidth', 1.5); % plot on new axes
hold on;
plot(z(indexOfInterest3),pns2(indexOfInterest3), 'k-.', 'LineWidth', 1.5); % plot on new axes
hold on;
plot(z(indexOfInterest3),p3uk(indexOfInterest3), 'k:', 'LineWidth', 2); % plot on new axes
axis tight
But my commands
xpos1 = [0.1 5 0];
ypos1 = [-0.08 4.8 0];
set( xlabh , 'position' , xpos1 );
set( ylabh , 'position' , ypos1 );
does not work, it is something like Matlab put something else over labels and my final plot is without axis labels. I tried to change place of that part of code, but it is the same, or when I put it after my normal plot it looks like Matlab forget for that plot and it remmebres only zommed part of plot.
What should I do?
3 Kommentare
Adam
am 28 Jan. 2020
Bearbeitet: Adam
am 28 Jan. 2020
I can't run your code beyond the lines you mention because Ree (and some subsequent variables) is not defined.
However, at the point where the code you mention is your axes limits are 0 to 1 in both x and y so trying to place labels with x or y values like 4.8 or 5 places them miles off the figure. A value of 0 or 1 will place the labels at either end of the axes, with values inbetween to place them in the middle, but anything above 1 is off the axes, likewise values < 0 are also off the axes, which is generally what you want, but only with values like -0.1 so they are alongside the axis ticks, as you have there for x. The y values are far too large though for the range of the axes at that point in the code. I don't know what happens to the axes limits subsequently since I don't have the data to run the rest of the code.
This is because, by default, the units used are data units (i.e. the same as on the axes). You can also change the 'Units' property of the label object if you find it easier to place the labels in normalized, pixels, etc instead.
3-element positions are what are needed though.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!