matlab对坐标轴的控制

最近Matlab的坐标轴整的我挺烦的,我总结一下其实它的功能挺强大,还是蛮好用的。

1.单独的应用

1.1给一个坐标系,

set(gca,'xticklabel',[]);  %不显示x轴的数据
set(gca,'Xtick',[]);   %不显示x轴的数据

1.2显示透明的坐标系

axes('Color','none')

1.3透明坐标系,x轴不显示

axes('Color','none','XColor','none')

1.4透明坐标系,y轴不显示

axes('Color','none','YColor','none')

1.5透明坐标系,左右y轴不显示

axes('Color','none','YColor','none','box','on')

1.6透明坐标系,上下x轴不显示

axes('Color','none','XColor','none','box','on')

2.组合应用

它们的组合可生成更多变换:

2.1显示左、下、右3个边

axes('XColor','none','box','on')
axes('Color','none','YColor','none')

2.2显示左、上、右3个边

axes('XColor','none','box','on')
axes('Color','none','YColor','none')
set(gca,'XAxisLocation','top')% x坐标轴到上面去

3.更复杂组合的应用

比如,只改变底部x轴的颜色,其他3条边都不改变。

方法一:推荐用这种

% put an empty axis on top and hide its ticks
x=1:10;
y=sin(x);
plot(x,y);
ax1=gca; %Current axes
set(ax1,'Xcolor','b') % Changing x-axis to blue
ax2=axes('Position',get(ax1,'Position'),...
'XAxisLocation','top','YAxisLocation','right','Color','none',...
'XTickLabels',[],'YTickLabels',[],...
'XTick',get(ax1,'XTick'));
linkaxes([ax1 ax2]); % for zooming and panning

方法二:

% Access the Axle and MajorTickChild properties (both storing LineStrip
% objects) of the XRuler property for the axes.Then can modify the
% ColorBinding and ColorData properties, using the VertexData property to
% do this.
XColor=[0 0 1];
hAxes=axes('Box','on','XColor',XColor);
drawnow;
hLines = hAxes.XRuler.Axle;

nLinePts = size(hLines.VertexData,2)./2;
hTicks = hAxes.XRuler.MajorTickChild
nTickPts = size(hTicks.VertexData,2)./2
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));

Leave a Reply

Your email address will not be published. Required fields are marked *