Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 仅更改底部X轴的颜色_Matlab_Plot_Matlab Figure - Fatal编程技术网

Matlab 仅更改底部X轴的颜色

Matlab 仅更改底部X轴的颜色,matlab,plot,matlab-figure,Matlab,Plot,Matlab Figure,我想将图形的底部x轴更改为蓝色,‍‍‍‍‍‍‍ 同时保持其他三面为黑色。‍‍‍‍‍‍‍‍‍‍‍‍‍ 有没有一种我不知道的简单方法?‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ 一种可能的解决方法是在顶部放置一个空轴并隐藏其刻度 示例: %Some random plot x = 0:0.1:4*pi; y = cos(x); plot(x,y); %Adjustments ax1 = gca; %Current axes

我想将图形的底部x轴更改为蓝色,‍‍‍‍‍‍‍ 同时保持其他三面为黑色。‍‍‍‍‍‍‍‍‍‍‍‍‍ 有没有一种我不知道的简单方法?‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

一种可能的解决方法是在顶部放置一个空轴并隐藏其刻度

示例:

%Some random plot
x = 0:0.1:4*pi;
y = cos(x);
plot(x,y);

%Adjustments
ax1 = gca;                %Current axes
%Now changing x-axis color to blue
set(ax1,'XColor','b');    %or ax1.XColor='b' for  >=R2014b 
ax2=axes('Position',get(ax1,'Position'),... %or ax1.Position for >=R2014b
    'XAxisLocation','top','YAxisLocation','right','Color','none',...
    'XTickLabels',[] ,'YTickLabels',[],...
     'XTick', get(ax1,'XTick'));  %or ax1.XTick for >=R2014b
linkaxes([ax1 ax2]);      %for zooming and panning


注意事项:这将
XTickLabels
的模式从
auto
更改为
manual
,因此任何缩放/平移都不会自动更新刻度颜色

您可以在较新版本的MATLAB中通过访问一些。具体地说,您希望访问轴的
XRuler
属性的
axe
MajorTickChild
属性(都存储
LineStrip
对象)。然后可以使用
VertexData
属性修改
ColorBinding
ColorData
属性:

XColor = [0 0 1];                             % RGB triple for blue
hAxes = axes('Box', 'on', 'XColor', XColor);  % Create axes
drawnow;                                      % Give all the objects time to be created
hLines = hAxes.XRuler.Axle;                   % Get the x-axis lines
nLinePts = size(hLines.VertexData, 2)./2;     % Number of line vertices per side
hTicks = hAxes.XRuler.MajorTickChild;         % Get the x-axis ticks
nTickPts = size(hTicks.VertexData, 2)./2;     % Number of tick vertices per side
set(hLines, 'ColorBinding', 'interpolated', ...
            'ColorData', repelem(uint8([255.*XColor 255; 0 0 0 255].'), 1, nLinePts));
set(hTicks, 'ColorBinding', 'interpolated', ...
            'ColorData', repelem(uint8([255.*XColor 255; 0 0 0 255].'), 1, nTickPts));
下面是情节:


注意:这是更新绘图的最后一步。调整轴的大小或对轴进行其他更改(特别是更改x轴记号的任何操作)可能会引发警告,并且无法正确渲染,因为上述设置已手动更改,因此在其他操作发生时不会自动更新。将其他属性设置为
“手动”
可能有助于避免这种情况,例如和。

非常感谢!看起来有点混乱,所以我会照你说的做,并将此作为最后一步。谢谢@SardarUsama,我会尝试一下。