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 have an unidimensional array (let's call it list)ranging from 0 to 86400, each one representing a second of a day (a day has 86400 secs).

For example,

list = {73496.3, 85974.6, 86085., 86136., 16.6256, 19.6975, 25.8896, 26.1856, 26.3937}

enter image description here

My goal is to change the ticks of plotted list with ListPlot, so that instead of the numbers, it gives you the hour. Also, there must be 24 ticks, each one representing one hour.

For example, the number 49616 would become 13:46:56

share|improve this question
    
ListPlot[list, PlotRange -> {0, 24 60 60}, Ticks -> {Automatic, Array[{3600 #, #} &, 24]}]? –  belisarius Feb 19 at 0:40
    
Well, I meant "13:00" and so, but I can use yours too. I don't know how I didn't think of that… Thanks –  Arcotick Feb 19 at 0:43
1  
ToString[DateString[ DateList[{0, 0, 0, 0, 0, #}]*{0, 0, 0, 1, 1, 1}, {"Hour", ":", "Minute", ":", "Second"}]] & /@ list will give you a list of string labels of the format you want corresponding to your list seconds values. These can be used to label as you see fit. –  rasher Feb 19 at 0:52

2 Answers 2

up vote 4 down vote accepted

You have a few options, the easiest of them being ListPlot[list/3600] :) To change the ticks to your desired format, you'll have to generate them manually. Here's an example:

With[{
    toHrMin = DateString[# {"Hour", ":", "Minute"}] &, 
    ticks = Range[0, 24, 4] 3600},

    ListPlot[list, Ticks -> {Automatic, Transpose@{ ticks, toHrMin /@ ticks}}]
]

You can change the last tick to 24:00 or (+1) 00:00 if you want.

share|improve this answer
    
@Kuba posted something like this in a comment and then deleted it: ListLinePlot[Quantity[list, "Seconds"], TargetUnits -> "Hours"] –  belisarius Feb 19 at 1:07
    
@belisarius I saw that and also agree with your deleted comment :) While those Quantity things are cool, it isn't a general solution, especially when the ticks need to be converted to something more complicated. Nevertheless, it's a good answer to this question and Kuba should post it as an answer. –  rm -rf Feb 19 at 1:17
    
At least it deserves to be kept as a comment. Not that I recommend it though:) –  belisarius Feb 19 at 1:24
    
@belisarius I've deleted it because of what rm-rf said :) but ok, I'll post this. p.s. I think "@" reminder is not working well lately, I've seen those comments by accident. –  Kuba Feb 19 at 6:08
    
@Kuba The ping thing works only if you already participated in the conversation. I knew you weren't going to be notified, but it wasn't important enough to try to get your attention. I just wanted to set the attribution for the idea –  belisarius Feb 19 at 14:10

Just another approach, Ticks have still to be reformatted but one does not have to worry about conversion from seconds to hours:

ListPlot[Quantity[list, "Seconds"], TargetUnits -> "Hours", 
          Ticks -> {Automatic,  Array[{#, StringForm["``:00", #]} &, 9, {0, 24}]}]

enter image description here

p.s. Array will not work this way for < V.9 so use Table instead.

share|improve this answer

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.