Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.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 仅删除轴线而不影响记号和记号标签_Matlab_Plot_Line_Axis_Matlab Figure - Fatal编程技术网

Matlab 仅删除轴线而不影响记号和记号标签

Matlab 仅删除轴线而不影响记号和记号标签,matlab,plot,line,axis,matlab-figure,Matlab,Plot,Line,Axis,Matlab Figure,是否有一种方法可以仅删除Matlab图形中的轴线,而不影响记号和记号标签 我知道,box可以切换上、右轴的线条和刻度,这对我来说非常合适。 但我的问题是,我想消除底部和左侧的线条(只有线条!),但保留记号和记号标签 有什么窍门吗?您可以通过在轴线上绘制一条白线来“擦除”轴线: plot(1:4,1:4) %// example plot box off %// remove outer border hold on a = axis; %// get axis size plot([a(1)

是否有一种方法可以仅删除Matlab图形中的轴线,而不影响记号和记号标签

我知道,
box
可以切换上、右轴的线条和刻度,这对我来说非常合适。
但我的问题是,我想消除底部和左侧的线条(只有线条!),但保留记号和记号标签

有什么窍门吗?

您可以通过在轴线上绘制一条白线来“擦除”轴线:

plot(1:4,1:4) %// example plot

box off %// remove outer border
hold on
a = axis; %// get axis size
plot([a(1) a(2)],[a(3) a(3)],'w'); %// plot white line over x axis
plot([a(1) a(1)],[a(3) a(4)],'w'); %// plot white line over y axis
结果:


正如@SardarUsama所指出的,在最近的Matlab版本中,您可能需要调整线宽以覆盖轴:

plot(1:4,1:4) %// example plot

box off %// remove outer border
hold on
a = axis; %// get axis size
plot([a(1) a(2)],[a(3) a(3)],'w', 'linewidth', 1.5); %// plot white line over x axis.
                                                     %// Set width manually
plot([a(1) a(1)],[a(3) a(4)],'w', 'linewidth', 1.5); 
R2014b之前的Matlab版本的解决方案 您可以引入一个新的白色边界框并将其置于顶部

// example data
x = linspace(-4,4,100);
y = 16 - x.^2;

plot(x,y); hold on
ax1 = gca;
set(ax1,'box','off')  %// here you can basically decide whether you like ticks on
                      %// top and on the right side or not

%// new white bounding box on top
ax2 = axes('Position', get(ax1, 'Position'),'Color','none');
set(ax2,'XTick',[],'YTick',[],'XColor','w','YColor','w','box','on','layer','top')

%// you can plot more afterwards and it doesn't effect the white box.
plot(ax1,x,-y); hold on
ylim(ax1,[-30,30])
重要的是停用第二个轴的刻度,以保持第一个轴的刻度

在解决方案中,如果随后更改轴特性,则打印的线将固定并保持在其初始位置。这不会发生在这里,他们会适应新的限制。对每个命令使用正确的句柄,不会有太多问题

更简单,但不适用于R2014b之前的Matlab版本。Yair Altman使用未记录的轴标尺演示了一种更干净的方法:

plot(x,y);
ax1 = gca;
yruler = ax1.YRuler;
yruler.Axle.Visible = 'off';
xruler = ax1.XRuler;
xruler.Axle.Visible = 'off'; %// note you can do different formatting too such as xruler.Axle.LineWidth = 1.5;
这种方法的一个很好的特点是,您可以分别格式化x轴和y轴的线条。

通过将标尺的
'LineStyle'
更改为
'none',
可以删除线条(适用于MATLAB R2014b和更高版本)

例如:

figure;
plot(1:4,'o-');  %Plotting some data
pause(0.1);      %Just to make sure that the plot is made before the next step
hAxes = gca;     %Axis handle
%Changing 'LineStyle' to 'none'
hAxes.XRuler.Axle.LineStyle = 'none';  
hAxes.YRuler.Axle.LineStyle = 'none';
%Default 'LineStyle': 'solid', Other possibilities: 'dashed', 'dotted', 'dashdot'



这与使用统治者的“可见”属性不同。

。。。我在属性中爬行,找不到任何可以将网格颜色与轴线分开的东西。谢谢。我也找不到任何财产。最接近的是轴关闭,但这也会删除记号、标签甚至背景。所以我想出了一个不太优雅的解决方案来覆盖轴心线:-)很酷的想法。Luis Mendo和thewaywewalk.顺便说一句,thewaywewalk,你的台词的颜色太棒了。你能分享线条图所用配色方案的细节吗?@SardarUsama谢谢你的提醒。我和你一样用R2015b。我答案中的图表可能是用R2010b获得的。在R2015b中,宽度
1.5
似乎工作正常(尽管它可能取决于系统)。我已经更新了答案,我只需要对y轴执行此操作,并找到了一个干净的方法,这要感谢未记录的Matlab:@Dan这太棒了+1-新的图形引擎使一切变得如此简单。“我只是希望有一天它会被记录下来。”丹用gca.YRuler.axe.Visible属性的回答是更好的解决方案。@hyiltiz,你认为这值得投反对票吗?特别是,因为我的答案也适用于旧的Matlab版本,而Dan的答案不适用!请告诉你自己,投反对票是为了什么!很公平。它们应该独立评估。尽管我仍然认为您的解决方案过于复杂,但它是通用的,可以直接应用于任何图形系统,而不知道这些图形系统是如何工作的(例如,知道一些秘密的未记录功能)。所以,独立考虑,我投你一票。Thx的教育!谢谢你的回答。对于那些像我一样试图弄清楚为什么带有
条的轴的
XRuler
没有消失的人:
bar
似乎有一个
ShowBaseLine
属性,必须关闭