Issues Using Functions to Rotate XTickLabels found on FEX

I am trying to rotate my x tick labels to a 60 degree angle. My labels are strings instead of integers. I have tried 3 separate functions from the file exchange site and I am having issues with all of them which I cannot figure out. Any help would be greatly appreciated on any aspect of my code or how I am implementing the functions.
Here is a piece of my code (Note: my data for this piece has 20,197 rows and therefore 20,197 data points for the date but it only spans about 25 days):
close all
y = data.rod1;
k = 1;
gmt = x(:,1);
% Conversion from serial date in GMT to PST
localt = gmt - 0.291666666395031;
date = datestr(localt,'mm/dd/yyyy');
%rotateXLabels
% Axial Load
figure(1)
plot(localt,y(:,22),'r',localt,y(:,23),'b')
grid on
set(gca,'XTickLabel',date)
rotateXLabels(gca,60)
set(gca,'XMinorTick','on','YMinorTick','on')
ylim([0 800])
title(['Rod ',num2str(k), ' Axial Force'])
xlabel('Date')
ylabel('Rod Load [kips]')
legend(['Rod',num2str(k),'N Load (Primary)'],['Rod',num2str(k),'S Load (Secondary)'])
set(legend,'FontSize',9)
When I use rotateXLabels.m (by Ben Tordoff) all the dates are the same on the x-axis (see first figure). In reality the dates should span from 7/31/2013 to 8/24/2013. I have double checked my input data that this is correct.
If I use xticklabel_rotate.m (by Brian Katz) the dates do not update when I zoom in on the plot (see second and third figures). From my understanding this is an issue with datetick
Lastly, I tried rotateticklabel.m (by Andrew Bliss) but I get this error:
Error using text
Each string specified must have a corresponding set of coordinates
Error in rotateticklabel (line 56)
th=text(b,repmat(c(1)-.1*(c(2)-c(1)),length(b),1),a,'HorizontalAlignment','right','rotation',rot);
I have tried different variations of each function and tried to eliminate my errors but I think I've just muddied my understanding. Ideally, I want to rotate my x ticks at 45 or 60 degrees, have then update when zooming, span the correct dates, and show each of the 25 days.
Thank you for any help!

 采纳的回答

I figured out the my issue with the first function. In the above code using the function rotateXLabels the line set(gca,'XTickLabel',date) is not needed and datetick is needed.
close all
x = data;
k = 1; % In original code this is in a loop, defined here for convenience
gmt = x(:,1); % Origianl serial date is in GMT(UTC)
localt = gmt - 0.291666666395031; % Conversion from serial date in GMT to PST
figure(1)
plot(localt,x(:,22),'r',localt,x(:,23),'b')
grid on
datetick('x','mm/dd/yyyy','keepticks')
rotateXLabels(gca, 45)
set(gca,'XMinorTick','on','YMinorTick','on')
% If want a specific amount of tickmarks. Note that may want to turn Minor
% Tick marks (above) off
% NumTicks = 26;
% L = get(gca,'XLim');
% set(gca,'XTick',linspace(L(1),L(2),NumTicks))
ylim([0 800])
title(['Rod ',num2str(k), ' Axial Force'])
xlabel('Date')
ylabel('Rod Load [kips]')
legend(['Rod',num2str(k),'N Load (Primary)'],['Rod',num2str(k),'S Load... (Secondary)'])
set(legend,'FontSize',9)
I have not solved my issues with the other two functions, I assume there are similar fixes as to the one stated here.

更多回答(0 个)

类别

产品

提问:

Pw
2014-3-26

编辑:

Pw
2014-3-28

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by