在 Matlab 中,如何改变轴的颜色?
In Matlab, How to change axes color?
谁,请告诉我如何改变坐标轴的颜色。当我 运行 下面的代码时,我得到了黑色轴上的时间和幅度值,这是默认值。我想改变它的颜色。我已经成功地改变了标签的颜色。
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')
如果您查看 subplot
you'll see a syntax that allows you to store the handle to your Axes
object to a variable, which you can use to specify Axes properties 的文档:
ax = subplot(___) returns the Axes object created. Use ax
to make future modifications to the axes. For a list of properties, see Axes Properties.
因为 plot
(with hold off
) resets the axes properties, you'll want to 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'});
给我们以下内容:
谁,请告诉我如何改变坐标轴的颜色。当我 运行 下面的代码时,我得到了黑色轴上的时间和幅度值,这是默认值。我想改变它的颜色。我已经成功地改变了标签的颜色。
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')
如果您查看 subplot
you'll see a syntax that allows you to store the handle to your Axes
object to a variable, which you can use to specify Axes properties 的文档:
ax = subplot(___) returns the Axes object created. Use
ax
to make future modifications to the axes. For a list of properties, see Axes Properties.
因为 plot
(with hold off
) resets the axes properties, you'll want to 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'});
给我们以下内容: