【问题标题】:Labeling different axis with two figures in one window matlab在一个窗口matlab中用两个图形标记不同的轴
【发布时间】:2014-12-11 03:13:51
【问题描述】:

我试图以不同的方式将轴标记为这些数字,我试图仅将一个 x 轴标记为“Time(s)”,并将第一个 y 轴标记为“f(t)”第二个为“g(t)”。在实现某种字体和大小的同时,我的书并没有明确说明如何做到这一点,而且互联网也不是很有帮助。

我知道我必须实现它,但我不知道在哪里:

% swEPSfigure.m
%
% Set the default font names and sizes for the eps figures
% prepared for Scientific Word
% In SW, a 65-50% reduction of the figures is normally done
% Full LaTeX commands can be used in the labels, legends, etc.
%
%
set(0,'DefaultAxesFontName','Times New Roman');
set(0,'DefaultTextFontName','Times New Roman');
set(0,'DefaultAxesFontSize',18);
set(0,'DefaultTextFontSize',18);
set(0,'defaulttextinterpreter','latex'); % Use LaTeX to add Math symbols
disp(' ');
disp(' Changing Default Font to Times New Roman');
disp(' Changing Default Font Size to 18');
disp(' ');

这是我当前的代码:

x = linspace(0,2);
y1 = sin(2*pi*x);
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x);

figure
subplot(2,1,1);
hPlot1 = plot(x,y1,'rs');

set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2)

subplot(2,1,2);
hPlot2 = plot(x,y2,'k*');

set(gca,'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2)

【问题讨论】:

    标签: matlab plot matlab-figure


    【解决方案1】:

    要更改标签,您需要获取标签本身的句柄。 固定代码:

    x = linspace(0,2);
    y1 = sin(2*pi*x);
    y2 = exp(-0.5*2*pi*x).*sin(2*pi*x);
    
    figure
    subplot(2,1,1);
    hPlot1 = plot(x,y1,'rs');
    
    set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2)
    set(get(gca,'XLabel'),'String','X axis label 1') %get the handle to XLabel and set its value 
    set(get(gca,'YLabel'),'String','Y axis 1') %get the handle to YLabel and set its value 
    
    subplot(2,1,2);
    hPlot2 = plot(x,y2,'k*');
    
    set(gca,'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:3)
    set(get(gca,'XLabel'),'String','X axis label 2') %get the handle to XLabel and set its value 
    set(get(gca,'YLabel'),'String','Y axis 2') %get the handle to YLabel and set its value 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      • 2018-01-21
      • 1970-01-01
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多