2017-03-17 89 views
0

有人请告诉我如何改变坐标轴的颜色。当我运行下面的代码时,我会以黑色的颜色显示轴上的时​​间和振幅值,这是默认值。我想改变它的颜色。我设法改变了标签的颜色。在Matlab中,如何更改轴的颜色?

dt = 0:0.2:50; 
y = 2*pi*sin(dt); 
subplot(211) 
plot(dt,y,'r'); 
grid on 
xlabel('Time','color','r') 
ylabel('Amplitude','color','r') 
z=pi*cos(dt); 
subplot(212) 
plot(dt,z,'g') 
grid on 
xlabel('Time','color','g') 
ylabel('Amplitude','color','g') 
+1

你读过[轴属性](https://se.mathworks.com/help/matlab/ref /axes-properties.html)? –

回答

1

如果你看一下subplot的文档,你会看到一个语法,可以让你把手存储到您的Axes对象变量,您可以使用指定Axes properties

ax = subplot(___)返回创建的Axes对象。使用ax将来对轴进行修改。有关房产列表,请参阅Axes Properties

因为plot(与hold off)复位轴的属性,你会想set'XColor''YColor'你们已经做出了地块之后。

例如:

dt = 0:0.2:50; 
y = 2*pi*sin(dt); 
ax(1) = subplot(211); 
plot(dt,y,'r'); 
grid on 
xlabel('Time','color','r') 
ylabel('Amplitude','color','r') 
z=pi*cos(dt); 
ax(2) = subplot(212); 
plot(dt,z,'g') 
grid on 
xlabel('Time','color','g') 
ylabel('Amplitude','color','g') 

set(ax, {'XColor', 'YColor'}, {'r', 'r'; 'g', 'g'}); 

给了我们如下:

yay

+0

通过这些词:*“我得到的时间和黑色的轴上的振幅值,这是默认的,我想改变它的颜色”*。我以为OP想要这个:'set(gca,'XColor','g','YColor','g');' –

+0

@SardarUsama oops – excaza