在MATLAB 2014b中用于plotyy的axis.XTickLabelrotation不起作用

时间:2015-02-23 11:46:30

标签: matlab plot

我在PC上安装了MATLAB 2014b代码:

h.XTickLabelRotation = 60;

旋转部分有效,但XTickLabel隐藏了甚至是'xlabel'。我有约会和时间时间在x轴上,想旋转60°。这是我写的代码:

x= {'09.02.2015 12:15:12' '09.02.2015 12:16:12' '09.02.2015 12:17:12'};
x = datenum(x,'dd.mm.yyyy HH:MM:SS');
y=[20 35 15];
plotyy(x,y,x,y-10)
datetick('x',31,'keepticks')
h=gca;
h.XTickLabelRotation = 60;
xlabel('Date&Time');

它适用于情节,但不适用于情节。有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:1)

我本来只是想指出一个类似于my answer to a recent question的解决方案。但它会产生一个相当丑陋的结果,特别是当您调整图形窗口时:

ew

我不确定旋转刻度标签是什么会混淆MATLAB的调整大小回调,但一种解决方法是从主轴而不是仅仅位置复制所有属性:

x = {'09.02.2015 12:15:12' '09.02.2015 12:16:12' '09.02.2015 12:17:12'};
x = datenum(x, 'dd.mm.yyyy HH:MM:SS');
y = [20 35 15];

h.myfig = figure;
h.ax1 = axes('Parent', h.myfig, 'Box', 'off');
hold(h.ax1, 'on');

plot(h.ax1, x, y);
datetick(h.ax1, 'x', 31, 'keepticks')
h.ax1.XTickLabelRotation = 60;
xlabel(h.ax1, 'Date&Time');

h.ax2 = copyobj(h.ax1, h.myfig);
cla(h.ax2);
plot(h.ax2, x, y-10);
h.ax2.YLim = h.ax1.YLim;
h.ax2.Color = 'None';
h.ax2.YAxisLocation = 'Right';

linkaxes([h.ax1, h.ax2], 'x'); % Link the 2 x axes for pan/zoom

A bit better

还有一些调整要做,但要好得多。

希望这有帮助!