1

I'm trying to fix a tricky issue with the axis on a plot I'm making in MATLAB. I want to display the dates and times of a temperature forecast (so the date labels plotted are essentially the hour the forecast is "valid" for, in 3-hour increments). The range of values is approximately 5 days, however my current plot is only showing the first five forecast times on the plot (instead the whole range, but only with a few points), as illustrated below:

The Incorrect time axes

I'm currently displaying these labels by creating a vector of strings containing the date labels (as generated from a matrix of DateVectors). The code for doing this is:

% Format all the dates into strings that can be displayed on the graph
for rid = 1:numRows
    rowdate = formattedDates(rid,:);   % DateVector for this forecast step
    fcstDateStrs{rid} = datestr(rowdate, 'dd-mmm-yyyy HHZ');
end

Then, I place these dates as the y-axis with the line set(gca,'XtickLabel', {}, 'YtickLabel', fcstDateStrs). Is there a way I can scale the labels on that axis to show all of the date labels properly scaled (so that the first one was like "03-Oct-2012 06Z" and the last one would be something like "08-Oct-2012 06Z")?

Devin
  • 996
  • 2
  • 8
  • 19

1 Answers1

1

You'll have to mess with the ytick property of the axes:

ticks = get(gca, 'ytick') 

will give you a vector of currently assigned tickmarks on the X-axis. You can use these to set the amount of ticks you want:

newTicks = linspace(ticks(1), ticks(end), numel(fcstDateStrs));
set(gca,...
    'Yticks'     , newTicks,...
    'YtickLabels', fcstDateStrs);

Note that since you've now set the ticks and tick labels manually, re-scaling the plot will be somewhat awkward -- this step is only to be executed once you're fairly sure the plot won't change much anymore.

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96