wd = WeatherData["SanDiego", "Temperature", {"Jan. 1, 2014", "Aug. 1, 2014", "Day"}];
(* for version 10+ evaluate: wd = wd // Normal // QuantityMagnitude; *)
sundays = Pick[wd[[All, 1]], DayName /@ wd[[All, 1]], Sunday];
wednesdays = Pick[wd[[All, 1]], DayName /@ wd[[All, 1]], Wednesday];
Ticks
at Wednesday noon:
ticks = MapIndexed[{AbsoluteTime[#] + 60 60 12,
Rotate["Week " <> ToString[First@#2], Pi/2]} &, wednesdays];
DateListPlot[wd, BaseStyle -> Thick, AspectRatio -> 1/4,
FrameTicks -> {ticks, Automatic, None, None},
GridLines -> {sundays, None}, ImageSize -> 900, Joined -> True]
Update:
You can also use DayMatchQ
instead of DayName[#]==...
:
Pick[wd[[All, 1]], DayMatchQ[#, Wednesday] & /@ wd[[All, 1]]] == wednesdays
(* True *)
Use different colors for different weeks:
wd = WeatherData["Kirkland", "Temperature", {"Jan. 1, 2014", "Aug. 1, 2014", "Day"}];
wd2 = wd /. {x_, y_} /; DayMatchQ[x, Sunday] :> Sequence[{x, y}, {x, y}];
wd2b = Split[wd2, ! (DayMatchQ[#[[1]], Sunday] && DayMatchQ[#2[[1]], Sunday]) &];
DateListPlot[wd2b, BaseStyle -> Thick, AspectRatio -> 1/4,
FrameTicks -> {ticks, Automatic, None, None}, GridLines -> {sundays, None},
ImageSize -> 900, Joined -> True, Filling -> Bottom]
Update 2: If there are gaps in the data so that some Sunday
s and/or Wednesday
s are skipped as in the example provided by @penguin77 in the comments, then you can use
dr = DateRange[wd[[1, 1]], wd[[-1, 1]]];
wednesdays = Pick[dr, DayMatchQ[#, Wednesday] & /@ dr];
sundays = Pick[dr, DayMatchQ[#, Sunday] & /@ dr];
Stealing and modifying @penguin77's great find we get a much cleaner way to get the dates we need for ticks and grid lines:
{wednesdays, sundays} = DayRange[## & @@ wd[[{1, -1}, 1]], #]&/@ {Wednesday, Sunday}
Splitting the data into separate weeks would be more involved in this case.