Skip to main content
added 219 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
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]

enter image description here

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]

enter image description here

Update 2: If there are gaps in the data so that some Sundays and/or Wednesdays 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.

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]

enter image description here

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]

enter image description here

Update 2: If there are gaps in the data so that some Sundays and/or Wednesdays 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];

Splitting the data into separate weeks would be more involved in this case.

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]

enter image description here

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]

enter image description here

Update 2: If there are gaps in the data so that some Sundays and/or Wednesdays 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.

added 520 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
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]

enter image description here

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]

enter image description here

Update 2: If there are gaps in the data so that some Sundays and/or Wednesdays 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];

Splitting the data into separate weeks would be more involved in this case.

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]

enter image description here

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]

enter image description here

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]

enter image description here

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]

enter image description here

Update 2: If there are gaps in the data so that some Sundays and/or Wednesdays 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];

Splitting the data into separate weeks would be more involved in this case.

added 91 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
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]

enter image description here

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]

enter image description hereenter image description here

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]

enter image description here

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:

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]

enter image description here

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]

enter image description here

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]

enter image description here

added 653 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 86 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading
added 47 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
added 30 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading