Adding text to axis label.

조회 수: 19 (최근 30일)
Ronald Bednarczyk
Ronald Bednarczyk 2020년 1월 15일
답변: Ronald Bednarczyk 2020년 1월 16일
I have several codes that read in data from Excel files based on parameter mneumonics. Those mneumonics are used to search another Excel file for a more descriptive parameter name. For example mneumonic ADCIAS_PCM2 will retieve INDICATED AIRSPEED (KTS) as a plot axis label. That axis label is universal and I use it for my x-axis. I want to add text at each end of the x-axis for REARWARD (at the negative x-axis end) and FORWARD (at the positive x-axis end). The current plot goes from -50 to +50. I used the following lines and they work, but the problem arises if the y-axis scaling is different the text will be higher or lower relative to the x-axis. How can I add this text such that it will stay inline with the xlabel?
text(-50,-0.1,'RWD','FontSize',8,'FontWeight','bold');
text( 47,-0.1,'FWD','FontSize',8,'FontWeight','bold');

답변 (2개)

Image Analyst
Image Analyst 2020년 1월 15일
Use the xlabel() and ylabel() commands instead.
xlabel('RWD','FontSize',8, 'FontWeight','bold');
If you want to use text() because you want the text to be in some box somewhere on the graph, then you'll have to replace those numbers for x and y in text() with something based on xlim() and ylim(). For example
% Place text 40% of the way over in x and 60% up in y.
caption = sprintf('The direction is %s', directionString);
xl = xlim;
yl = ylim;
xt = xl(1) + 0.4 * (xl(2) - xl(1));
yt = yl(1) + 0.6 * (yl(2) - yl(1));
text(xt, yt, caption,'FontSize',8, 'FontWeight','bold', 'Horizontal Alignment', 'left');

Ronald Bednarczyk
Ronald Bednarczyk 2020년 1월 16일
I did this instead. The maxy just sets the ylim to the next highest decimal.
xlabel(X_label_txt);
ylabel(cell2mat(Y_axis_label_cell(param_no)));
legend('show','Location','northwest');
xlim([-50 50]); %Fixed X-axis scale
if max(ylim)>=1
maxy=ceil(max(ylim));
elseif max(ylim)*10>=1
maxy=ceil(max(ylim)*10)/10;
elseif max(ylim)*100>=1
maxy=ceil(max(ylim)*100)/100;
end
set(gca, 'YLim', [0, maxy]);
grid on;
%Set X and Y-axis tick mark & label font type & size
ax = gca;
ax.YAxis.TickLabelFormat = '%,.2f';
ax.FontSize = 8;
ax.FontName = 'Courier';
ax.FontWeight = 'bold';
ax.GridColor = [0, 0, 0];
ax.GridLineStyle = ':';
ax.GridAlpha = 0.8;
ytext=-0.2*maxy;
text(-50,ytext,'LSF','FontSize',8,'FontWeight','bold');
text( 47,ytext,'RSF','FontSize',8,'FontWeight','bold');

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by