poster
2019-12-10, 20:41
我想编辑正在显示的一系列图像中的轴。
这是我的形象:
https://i.stack.imgur.com/O5qpq.png (https://i.stack.imgur.com/O5qpq.png)
如您所见,从上到下的范围是0到大约500。我可以反转吗?另外,我想镜像显示的图像,以便从左到右开始...或者,如果可能的话,让轴从右到左显示。
回答:
要反转一个轴,可以将当前轴 (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/gca.html)的'XDir' (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#XDir)或'YDir' (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#YDir)属性设置为'reverse' :
set(gca,'XDir','reverse'); %# This flips the x axis 请记住,以这种方式翻转轴也会翻转绘图中的所有内容。这可能不是您要为y轴执行的操作。您可能只想翻转y轴标签 ,可以通过以下方式修改'YTickLabel' (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#YTickLabel)属性来完成:
yLimits = get(gca,'YLim'); %# Get the y axis limits yTicks = yLimits(2)-get(gca,'YTick'); %# Get the y axis tick values and %# subtract them from the upper limit set(gca,'YTickLabel',num2str(yTicks.')); %'# Convert the tick values to strings %# and update the y axis labels
更多&回答... (https://stackoverflow.com/questions/2865600)
这是我的形象:
https://i.stack.imgur.com/O5qpq.png (https://i.stack.imgur.com/O5qpq.png)
如您所见,从上到下的范围是0到大约500。我可以反转吗?另外,我想镜像显示的图像,以便从左到右开始...或者,如果可能的话,让轴从右到左显示。
回答:
要反转一个轴,可以将当前轴 (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/gca.html)的'XDir' (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#XDir)或'YDir' (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#YDir)属性设置为'reverse' :
set(gca,'XDir','reverse'); %# This flips the x axis 请记住,以这种方式翻转轴也会翻转绘图中的所有内容。这可能不是您要为y轴执行的操作。您可能只想翻转y轴标签 ,可以通过以下方式修改'YTickLabel' (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/axes_props.html#YTickLabel)属性来完成:
yLimits = get(gca,'YLim'); %# Get the y axis limits yTicks = yLimits(2)-get(gca,'YTick'); %# Get the y axis tick values and %# subtract them from the upper limit set(gca,'YTickLabel',num2str(yTicks.')); %'# Convert the tick values to strings %# and update the y axis labels
更多&回答... (https://stackoverflow.com/questions/2865600)