Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm not sure how to add time format to bar plots. I'd like to be able to make one bar plot for one data set and another for another data set and then combine them, but I don't know how to offset each bar from the origin so they can overlap at the right times.

See image for an idea:

concept

share|improve this question
2  
Can you provide a small (but working) code sample of what you have so far? –  ssch Oct 20 '13 at 16:33
    
How many bars do you want to display at one time? –  David Carraher Oct 20 '13 at 16:42
    
You may want to consider Gantt charts as a more general approach: demonstrations.wolfram.com/GanttChartsAndNetworkDiagrams –  David Carraher Oct 20 '13 at 19:07
add comment

2 Answers

up vote 9 down vote accepted

Assuming two time intervals,

t1 = "5:20"; t2 = "7:20";
t3 = "6:01"; t4 = "8:07";

toMin[t_] := ToExpression /@ StringSplit[t, ":"] /. {h_, m_} :> 60 h + m

Graphics[{  {Opacity[.4], EdgeForm[Black],
  Gray, Rectangle[{toMin@t1, 0}, {toMin@t2, 1}],
  Red, Rectangle[{toMin@t3, .5}, {toMin@t4, 1.5}]},
  Text[t1, Offset[{0, -20}, {toMin@t1, 0}]],
  Text[t2, Offset[{0, -20}, {toMin@t2, 0}]],
  Text[t3, Offset[{0, 50}, {toMin@t3, 0}]],
  Text[t4, Offset[{0, 50}, {toMin@t4, 0}]]},
  BaseStyle -> 20,
  AspectRatio -> 1/12]

times


Alternative Format

This approach can accommodate a larger number of time intervals.

t1 = "5:20"; t2 = "7:20";
t3 = "6:01"; t4 = "8:07";
t5 = "1:23"; t6 = "4:19";
t7 = "3:14"; t8 = "4:51";

toMin[t_] := ToExpression /@ StringSplit[t, ":"] /. {h_, m_} :> 60 h + m;
seg[start_, end_, color_, ht_] := {EdgeForm[{Thickness[.003], color}], 
  Rectangle[{toMin@start, ht}, {toMin@end, ht + 1}],
  Black, 
  Text[start <> " \[RightArrow] ", {toMin@start, ht + .5}, {1, 0}], 
  Text[" \[LeftArrow] " <> end, {toMin@end, ht + .5}, {-1, 0}]};

 Graphics[{
  {White,
  seg @@@ {{t1, t2, Gray, 0}, {t3, t4, Red, 2}, {t5, t6, Blue, 4}, 
  {t7, t8,  Darker@Green, 6}}}},
  GridLines -> {toMin /@ {t1, t2, t3, t4, t5, t6, t7, t8}, {}},
  FrameTicks -> {Table[{60 k, k} /. {_Rational -> "", 0 -> 12}, {k, 0, 9, 1/4}], {}},
  FrameLabel -> {"PM"},
  ImageSize -> 600,
  PlotRange -> {{0, 540}, Automatic},
  PlotRangePadding -> 3,
  Frame -> {True, False},
  BaseStyle -> 16,
  AspectRatio -> 1/6]

schedule

share|improve this answer
add comment

The following should be enough to get you started:

f[min_, max_, pos_] := 
 Sequence[Rectangle[{min, pos}, {max, pos - 0.5}], {Opacity[1], 
   Text[Style[min, Large, Bold], {min, pos}], 
   Text[Style[max, Large, Bold], {max, pos}]}]
Graphics[{Opacity[0.5], Red, f[1, 2, 0], Blue, f[1.5, 3, .1]}]

enter image description here

You still need to write a function that transforms your times into horizontal coordinates …

share|improve this answer
    
Your code appears to have an error in it: $Failed –  David Carraher Oct 20 '13 at 19:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.