0

For a plot, like the one attached, is there a way to introduce a dual category axis? A (poorly drawn) example can be seen attached also.

The report ideally should be auto generated, so setting static day names are not ideal..

EDIT: I should also mention it would be great to have the hours start again each day, 0-24,0-24,0-24 etc

Example data

Ideal Result

AMcNall
  • 529
  • 1
  • 5
  • 23

2 Answers2

2

Not sure about the days, but I have a suggestion for the hours. Imagine the following:

hours = 0:70;
data=rand(size(hours));
plot(hours,data,'*')
xlabel('Hours of day')

This gives the following plot:

enter image description here

Now you need to edit the labels used by the x-axis. Here's one way to do it (not necessarily the most elegant because you are dealing with cell arrays and have to convert things back and forth between string and numerical data type, but it seems to work, at least in Octave):

temp = get(gca,'xticklabel');
for k=1:length(temp)
    temp{k} = num2str(mod(str2num(temp{k}),24));
end
set(gca,'xticklabel',temp)

Which gives the following graph:

enter image description here

Good luck with adding the days below that!! (maybe using the text command in a clever way)

am304
  • 13,758
  • 2
  • 22
  • 40
2

Here is a very custom way using text annotations. You might need to add some minor changes to fit your data.

clc
clear

x = 1:80;

HourValues = repmat([0 10 20],1,3);
DaysString = {'Mon' 'Tue' 'Wed'};

NumDays = numel(DaysString);

plot(x,rand(1,80))

set(gca,'XTickLabel',HourValues) % Set xtick labels

xlimit = get(gca,'XLim'); % Get x and y- limits
ylimit = get(gca,'YLim');



% May need some adaptation to fit your data
for k = 1:NumDays       
    text((NumDays*k-2)*10,ylimit(1)-.06,DaysString{k},'FontSize',14,'HorizontalAlignment','Center')
end

text(xlimit(2)/2,ylimit(1)-0.1,'Hour of day','FontSize',16,'HorizontalAlignment','Center')

Giving something like this:

enter image description here

Benoit_11
  • 13,905
  • 2
  • 24
  • 35