Show time labels on multi (6) axes plot
이전 댓글 표시
I had written the following code to create a plot with 6 axes, outputting the handle for each axes. This code may be copy and pasted as desired.
The problem that I am facing now is trying to represent the x axes labels as time in 'HH:MM:SS.FFF' format. I have a time vector in which I created using the start time of my file and a sampling frequency of 5Hz, and the total length of my data. This vector looks something like this;
(assume start_time 1241)
time_sim=datenum(start_time,'HHMM'): ...
datenum('0.2','SS.FFF'): ...
datenum(start_time,'HHMM')+ ...
datenum(start_time,'HHMM')*(length(data)-1);
When converting this back using datestr and a format of 'HH:MM:SS.FFF' this seems to be correct. When creating my multi axes plot, I use the time to get the limits; however, my axes is not setting correctly to those limits. After plotting, I am still unable to set the xAxis to a readable form with the time 'HH:MM:SS.FFF'.
I have tried using:
1) datetick
2) set(handle,'XTickLabel',datestr(time))
Any any variation in between with no luck. Ultimately I would like an x-axis, neatly showing times from start to end. Any help is appreciated. I have included my multi-axes plotting code to see if someone can find what I am missing:
function [h1, h2, h3, h12, h22, h32] = multi_axes_plot(time)
% Some initial computations:
axesPosition = [0.15 .15 .7 .6]; % Axes position
yWidth = .05; % y axes spacing
xLimit = [min(time) max(time)]; % Range of x values
xOffset = -yWidth*diff(xLimit)/axesPosition(3);
% Create the figure and axes:
figure('Units','normalized','Position',[0 0 1 1]);
h1 = axes('Units','normalized','Position',axesPosition,...
'Color','w','XColor','k','YColor','k',...
'XLim',xLimit,'NextPlot','add');
h2 = axes('Units','normalized','Position',axesPosition+yWidth.*[-1 0 1 0],...
'Color','none','XColor','k','YColor','r',...
'XLim',xLimit+[xOffset 0],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
h3 = axes('Units','normalized','Position',axesPosition+yWidth.*[-2 0 2 0],...
'Color','none','XColor','k','YColor','g',...
'XLim',xLimit+[2*xOffset 0],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
h12 = axes('Units','normalized','Position',get(h1,'Position'),...
'Color','none','XColor','k','YColor','m',...
'XLim',xLimit,'YAxisLocation','right','NextPlot','add');
h22 = axes('Units','normalized','Position',get(h2,'Position')+yWidth*[1 0 0 0],...
'Color','none','XColor','k','YColor','b',...
'XLim',xLimit-[0 xOffset],...
'XTick',[],'XTickLabel',[],'YAxisLocation','right','NextPlot','add');
h32 = axes('Units','normalized','Position',get(h3,'Position')+[0.1 0 0 0],...
'Color','none','XColor','k','YColor','c',...
'XLim',xLimit-[0 2*xOffset],...
'XTick',[],'XTickLabel',[],'YAxisLocation','right','NextPlot','add');
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!