gpt4 book ai didi

matlab - 标记不同的图形、字体、大小 MATLAB

转载 作者:太空宇宙 更新时间:2023-11-03 19:53:31 25 4
gpt4 key购买 nike

我正在尝试基本上复制这张图以供我最后的练习使用,但我不明白如何更改字体、大小或标记轴。简而言之,我需要从我的代码中完全复制这张图。我需要字体为 times new roman,大小为 18,标记大小为 8。我如何将我的代码格式化成这样? enter image description here

这是我的代码:

clear
clc

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');
ylabel('f(t)')
set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2)

subplot(2,1,2);
hPlot2 = plot(x,y2,'k*');
xlabel('Time(s)')
ylabel('g(t)')
set(gca,'YLim',[-0.2,0.6],'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2)

最佳答案

下面的代码:

%// x = linspace(0,2); %// changed that to respect where the markers are on your example figure 
x = 0:0.1:2 ;
y1 = sin(2*pi*x);
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x);

figure
h.axtop = subplot(2,1,1) ;
h.plottop = plot(x,y1,'LineStyle','-','Color','r', ...
'Marker','s', ...
'MarkerEdgeColor','k', ...
'MarkerFaceColor','none', ...
'MarkerSize',8) ;
set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2)
h.ylbl(1) = ylabel('\itf(t)') ; %// label is set in "italic" mode with the '\it' tag at the beginning

h.axbot = subplot(2,1,2);
h.plotbot = plot(x,y2,'-ks', ...
'Marker','*', ...
'MarkerEdgeColor','r', ...
'MarkerSize',8) ;
set(gca,'YLim',[-0.2,0.6],'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2)
h.xlbl(1) = xlabel('Time(s)') ;
h.ylbl(2) = ylabel('\itg(t)') ; %// label is set in "italic" mode with the '\it' tag at the beginning

%// create the "text" annotations
h.txttop = text(0.5,1.5, 'Harmonic force \itf(t)=sin(\omegat)' , 'Parent',h.axtop ) ; %// note the 'parent' property set to the TOP axes
h.txtbot = text(0.5,0.3, 'Forced response \itg(t)=e^{\zeta\omegat} sin(\omegat)' , 'Parent',h.axbot ) ; %// note the 'parent' property set to the BOTTOM axes

%// set the common properties for all text objects in one go
set( [h.xlbl h.ylbl h.txttop h.txtbot] , 'FontName','Times New Roman' , 'FontSize',18)

会产生下图: figure

请注意图形对象的句柄是如何保存并在以后重新用于设置属性的。如果多个图形对象(甚至不同的)具有相同的属性,则可以一次性将此属性赋值给所有的图形对象。

看Matlab text有关如何在图形上放置注释的更多详细信息的功能文档。

关于matlab - 标记不同的图形、字体、大小 MATLAB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27417887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com