如何在MATLAB中修复x tick标签?

时间:2015-11-09 15:42:17

标签: matlab

我在Excel中有一些数据包含以下信息

Rx        SD      TP         Time
-64.27  1.66    20.99   15:36:14.58
-62     1.58    29.22   15:38:50.53
-62.33  1.55    29.23   15:41:27.53
-61.17  1.33    29.26   15:44:04.54
-60.15  1.05    29.22   15:46:41.52
-62.53  1.46    29.14   15:49:18.55
-64.1   1.48    25.07   15:51:55.50
-62.45  1.52    28.91   15:54:31.51
-65.14  1.41    21.86   15:57:08.46
-63.61  2.05    20.05   15:59:44.50



.
.
.
.
-59.56  0.6    29.1     17:15:20.57
-59.71  0.68    29.1    17:17:57.58
-59.44  0.57    29.14   17:20:34.59
-59.62  0.64    29.12   17:23:11.60
-59.58  0.64    29.15   17:25:48.51

我使用以下方法从excel中提取了信息:

[tp,t] = xlsread(data,xlsheet,xlrange)

其中t存储时间值。

我在matlab中提取了Rx,SD和TP的每个值:

tp_w= tp(:,3);
rx_pow= tp(:,1);
rx_err= tp(:,2);
t1=datenum(t);

对于我的图表,我需要在subplot (2,1,1)中绘制TP与时间的关系,并在subplot (2,1,2)中绘制SD与时间的Rx。 图:我用以下方法绘制了下图。

a1=subplot(2,1,1)
plot(t1,tp_w,'-gd','Linewidth',1);
xlim([min(t1),max(t1)])
ylim([0,30])
set(gca,'yTick',0:1:30)
datetick('x',13) 
xlabel('Time);
ylabel('TP ');
grid on; 

对于有错误的Rx我正在使用errobar函数:

a2=subplot(2,1,2)
errorbar(t1,rx_pow,rx,'-rd','Linewidth',1);
xlim([min(t1),max(t1)])
ylim([-70,-53])
set(gca,'yTick',-70:0.5:-53)
datetick('x',13) 
xlabel('Time);
ylabel('Rx ');
grid on; 

linkaxes([a1,a2],'x')

hold on

enter image description here

Q1:我的数据从15:36:15.73开始,到17:25:48.51结束。如何让我的图表从15:36:00开始,到17:25:48.51结束,这样我在开始和结束时都没有差距。

Q2:如何添加更多x-tick以便在X轴上添加更多标签?例如。 16:45:00...17:00:00...17:15:00等等

编辑1:添加绘图功能后更新:

h = gca;
set(h, 'XTick', [(55200/86400):(90/86400):(63000/86400)]); 
datetick('x', 13', 'keeplimits', 'keepticks');

enter image description here

EDIT2:进行必要的更改 评论XTick:

a1=subplot(2,1,1)
plot(t1,tp_w,'-gd','Linewidth',1);
xlim([min(t1),max(t1)])
% h = gca;
% set(h,'XTick',[(55100/86400):(900/86400):(62140/86400)]); 
ylim([0,30])
set(gca,'yTick',0:1:30)
datetick('x', 13,'keepticks','keeplimits');
xlabel('Time');
ylabel('TP ');
grid on; 

Commenting Xtick and using datetick('x', 13,'keepticks','keeplimits')

最后保留datetick并评论linkaxes:

a1=subplot(2,1,1)
plot(t1,tp_w,'-gd','Linewidth',1);
xlim([min(t1),max(t1)])
h = gca;
set(h,'XTick',[(55100/86400):(900/86400):(62140/86400)]); 
ylim([0,30])
set(gca,'yTick',0:1:30)
datetick('x', 13,'keepticks','keeplimits');
xlabel('Time');
ylabel('TP ');
grid on; 

没有轴: Commenting linkaxes

get(gca)的结果(linkaxes off + datetick保持在最后):

get(gca)
    ActivePositionProperty = outerposition
    ALim = [0 1]
    ALimMode = auto
    AmbientLightColor = [1 1 1]
    Box = off
    CameraPosition = [0.5 0.5 9.16025]
    CameraPositionMode = auto
    CameraTarget = [0.5 0.5 0.5]
    CameraTargetMode = auto
    CameraUpVector = [0 1 0]
    CameraUpVectorMode = auto
    CameraViewAngle = [6.60861]
    CameraViewAngleMode = auto
    CLim = [0 1]
    CLimMode = auto
    Color = [1 1 1]
    CurrentPoint = [ (2 by 3) double array]
    ColorOrder = [ (7 by 3) double array]
    DataAspectRatio = [1 1 1]
    DataAspectRatioMode = auto
    DrawMode = normal
    FontAngle = normal
    FontName = Helvetica
    FontSize = [10]
    FontUnits = points
    FontWeight = normal
    GridLineStyle = :
    Layer = bottom
    LineStyleOrder = -
    LineWidth = [0.5]
    MinorGridLineStyle = :
    NextPlot = replace
    OuterPosition = [0 0 1 1]
    PlotBoxAspectRatio = [1 1 1]
    PlotBoxAspectRatioMode = auto
    Projection = orthographic
    Position = [0.13 0.11 0.775 0.815]
    TickLength = [0.01 0.025]
    TickDir = in
    TickDirMode = auto
    TightInset = [0.0392857 0.0404762 0.00892857 0.0190476]
    Title = [174.006]
    Units = normalized
    View = [0 90]
    XColor = [0 0 0]
    XDir = normal
    XGrid = off
    XLabel = [175.006]
    XAxisLocation = bottom
    XLim = [0 1]
    XLimMode = auto
    XMinorGrid = off
    XMinorTick = off
    XScale = linear
    XTick = [ (1 by 11) double array]
    XTickLabel = [ (11 by 3) char array]
    XTickLabelMode = auto
    XTickMode = auto
    YColor = [0 0 0]
    YDir = normal
    YGrid = off
    YLabel = [176.006]
    YAxisLocation = left
    YLim = [0 1]
    YLimMode = auto
    YMinorGrid = off
    YMinorTick = off
    YScale = linear
    YTick = [ (1 by 11) double array]
    YTickLabel = [ (11 by 3) char array]
    YTickLabelMode = auto
    YTickMode = auto
    ZColor = [0 0 0]
    ZDir = normal
    ZGrid = off
    ZLabel = [177.006]
    ZLim = [0 1]
    ZLimMode = auto
    ZMinorGrid = off
    ZMinorTick = off
    ZScale = linear
    ZTick = [0 0.5 1]
    ZTickLabel = 
    ZTickLabelMode = auto
    ZTickMode = auto

    BeingDeleted = off
    ButtonDownFcn = 
    Children = []
    Clipping = on
    CreateFcn = 
    DeleteFcn = 
    BusyAction = queue
    HandleVisibility = on
    HitTest = on
    Interruptible = on
    Parent = [1]
    Selected = off
    SelectionHighlight = on
    Tag = 
    Type = axes
    UIContextMenu = []
    UserData = []
    Visible = on

1 个答案:

答案 0 :(得分:0)

我认为你正在做正确的事情来设定限制。问题是,datetick与他们混在一起。

首先,要更改刻度数,请使用轴的“XTick”属性。例如:

h = gca;
set(h, 'XTick', [(55800/86400):(900/86400):(63000/86400)]);  %% This should do 15-minute increments...change the "900" to the seconds value that you want for intervals

棘手的是,除非你明确告诉不要,否则使用你的限制和刻度标记会使用datetick。

datetick('x', 13', 'keeplimits', 'keepticks');