0
$\begingroup$

I have some data which are key value pairs of Unix timestamp to integer.

I parse them into a list of { date object, integer } pairs like so:

{FromUnixTime[#[[1]]], #[[2]]} & /@ data;

When I create a plot of the data using DateListPlot, the times shown on the x-axis ticks are in my local time zone.

How can I change the time zone used in the ticks?

(I tried passing the TimeZone->"GMT" to the FromUnixTime call, but that had no effect.)

Here is the code I am using:

SetDirectory[NotebookDirectory[]];
data = Import["memory_usage.csv"];
memoryUsage = {FromUnixTime[#[[1]]], #[[2]]} & /@ data;
memoryUsageRSS = {FromUnixTime[#[[1]]], #[[3]]} & /@ data;
usedMemoryPeak = {FromUnixTime[#[[1]]], #[[4]]} & /@ data;
DateListPlot[
 {memoryUsage, memoryUsageRSS, usedMemoryPeak},
 PlotLegends -> {"Memory Usage", "Process RSS", "Peak Memory Usage"},
 Frame -> True,
 FrameLabel -> "Bytes",
 Filling -> {1 -> {{2}, LightRed}},
 PlotRange -> {0, All},
 ImageSize -> 1200,
 DateTicksFormat -> {"MonthShort", "/", "Day", " ", "Hour12Short","AMPM"}
]

And some example of the contents of the .csv file:

1519940635,  3417080808,  4131508224,  4023456800,1.210
1519940695,  3423336608,  4131033088,  4023456800,1.210
1519940755,  3416913176,  4132491264,  4023456800,1.210
1519940815,  3359862240,  4081823744,  4023456800,1.210
1519940875,  3362972080,  4078796800,  4023456800,1.210
1519940935,  3353922880,  4102684672,  4023456800,1.220
1519940995,  3236740296,  3998560256,  4023456800,1.240
1519941055,  3293770672,  4026695680,  4023456800,1.220
1519941115,  3283204080,  4044091392,  4023456800,1.230
1519941175,  3252767768,  4001890304,  4023456800,1.230
1519941236,  3275617792,  4028063744,  4023456800,1.230
1519941296,  3212421536,  3987374080,  4023456800,1.240
1519941356,  3174281760,  3943858176,  4023456800,1.240
1519941416,  3192086208,  3965349888,  4023456800,1.240
1519941476,  3165287088,  3927031808,  4023456800,1.240
1519941536,  3163575464,  3936268288,  4023456800,1.240
1519941596,  3134785832,  3934359552,  4023456800,1.260
1519941656,  3062644488,  3873013760,  4023456800,1.260
1519941716,  3094924312,  3913363456,  4023456800,1.260
1519941776,  3049124280,  3847319552,  4023456800,1.260
1519941836,  3032605872,  3844624384,  4023456800,1.270
1519941896,  3086601680,  3880878080,  4023456800,1.260
1519941956,  3062714976,  3854192640,  4023456800,1.260
1519942016,  3142868144,  3916312576,  4023456800,1.250
1519942076,  3159228800,  3936288768,  4023456800,1.250
1519942136,  3203715072,  3960463360,  4023456800,1.240
1519942196,  3302066920,  4043214848,  4023456800,1.220
1519942256,  3286603528,  4024782848,  4023456800,1.220
1519942316,  3349171360,  4079497216,  4023456800,1.220
1519942376,  3365035360,  4078395392,  4023456800,1.210
1519942436,  3424011720,  4126691328,  4023456800,1.210
1519942496,  3455901768,  4147798016,  4023456800,1.200
1519942556,  3490703496,  4165046272,  4023456800,1.190
1519942616,  3590770592,  4255629312,  4023456800,1.190
1519942676,  3553709552,  4207505408,  4023456800,1.180
1519942736,  3643557312,  4273332224,  4023456800,1.170
1519942796,  3617374176,  4262977536,  4023456800,1.180
1519942856,  3716079936,  4401905664,  4023456800,1.180
1519942916,  3776007992,  4482637824,  4023456800,1.190
1519942976,  3755468528,  4479623168,  4023456800,1.190
1519943036,  3855655496,  4597735424,  4023456800,1.190
1519943096,  3815688408,  4580679680,  4023456800,1.200
1519943156,  3931530568,  4709609472,  4023456800,1.200
1519943216,  3920809328,  4727230464,  4023456800,1.210
1519943277,  3887373776,  4660908032,  4023456800,1.200
1519943337,  3945285664,  4751241216,  4023456800,1.200
1519943397,  3931134472,  4733198336,  4023456800,1.200
1519943457,  3926123824,  4687958016,  4023456800,1.190
1519943517,  3990009544,  4782391296,  4023456800,1.200
1519943577,  3903503360,  4691968000,  4023456800,1.200
1519943637,  3922165328,  4698497024,  4023456800,1.200
1519943697,  3900528912,  4681093120,  4023456800,1.200
1519943757,  3956621776,  4736413696,  4023456800,1.200
1519943817,  3891338856,  4678193152,  4023456800,1.200

Even if I change the timezone of the date objects, I still see the graph in local time.

$\endgroup$
  • $\begingroup$ Cant you just use TimeZoneConvert on the output of FromUnixTime? $\endgroup$ – Carl Woll Mar 1 '18 at 23:45
  • $\begingroup$ @CarlWoll - Nope, I tried that too, and it still shows up in my local timezone on the plot, even though the date objects themselves show GMT. $\endgroup$ – jimpudar Mar 1 '18 at 23:49
  • $\begingroup$ Example data and your DateListPlot call would be useful to people who wanted to help. $\endgroup$ – Carl Woll Mar 2 '18 at 0:04
  • $\begingroup$ @CarlWoll - added these. Thanks! $\endgroup$ – jimpudar Mar 2 '18 at 0:29
1
$\begingroup$

FromUnixTime[..., TimeZone -> timezone] does work at least in Mathematica 11.3 Win7.

Mathematica graphics

Module[
 {
  timezone = -5,
  data = Import["https://pastebin.com/raw/X83JM132", "CSV"],
  times, memoryUsage, memoryUsageRSS, usedMemoryPeak
  },
 times = Map[FromUnixTime[#, TimeZone -> timezone] &, data[[All, 1]]];
 memoryUsage = Transpose[{times, data[[All, 2]]}];
 memoryUsageRSS = Transpose[{times, data[[All, 3]]}];
 usedMemoryPeak = Transpose[{times, data[[All, 4]]}];
 DateListPlot[
  {memoryUsage, memoryUsageRSS, usedMemoryPeak}
  , PlotLegends -> {"Memory Usage", "Process RSS", "Peak Memory Usage"}
  , Frame -> True
  , FrameLabel -> "Bytes"
  , Filling -> {1 -> {{2}, LightRed}}
  , PlotRange -> {0, All}
  , ImageSize -> 500
  , DateTicksFormat -> {"MonthShort", "/", "Day", " ", "Hour12Short", 
    "AMPM"}
  ]
 ]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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