How to reset XTickLabel to default

爷,独闯天下 提交于 2019-12-23 16:04:59

问题


In R2010b, I can reset the tick labels to auto thru figure editor,
but I'd like to reset them to default programmatically
I tried

set(gca,'XTickLabel','auto')

But it displays 'auto' at each tick... Any hint ?


回答1:


You need to set XTickLabelMode to 'auto':

set(gca,'XTickLabelMode','auto')

Tick label modes are set to 'manual' when you specify tick labels. So, you need to turn it back to 'auto'.




回答2:


OK, I finally found this way:

set(gca,'XTickLabel', num2str(get(gca,'XTick')'));

I read the ticks and transform them back to strings...

EDIT: note that this a workaround that happens to work if you don't zoom nor resize the figure, but which is not robust to zoom/resize because the XTickLabelMode remains 'manual' and thus the XTickLabel won't be updated when you zoom.

I added this answer because this is the first thing I found (and others might find too).
The reason why it is not the preferred way is more usefull than the answer itself, thus this edit.

The right solution to do it, is the one that I accepted.



来源:https://stackoverflow.com/questions/13909880/how-to-reset-xticklabel-to-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!