2
$\begingroup$

How can I use "MinTemperature", "MaxTemperature", and "Temperature" properties of WeatherData for one or more cities in one line of code?

$\endgroup$
  • 4
    $\begingroup$ What's the point of one line of code? Do you intend anything more complex than, say, this variant of an example from the help page? DateListPlot[WeatherData["KABQ", #, {2008, 3}], Joined -> True] & /@ {"Pressure", "Temperature", "WindSpeed"} // TableForm $\endgroup$ – whuber Nov 15 '12 at 6:00
  • 3
    $\begingroup$ "one line of code" is overrated. $\endgroup$ – rm -rf Nov 15 '12 at 6:08
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2)Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign` $\endgroup$ – chris Nov 15 '12 at 8:04
  • $\begingroup$ @Soum: take a look at Map[] in the help files. $\endgroup$ – Aart Goossens Nov 15 '12 at 11:22
3
$\begingroup$

Here's something you could build on. It only shows min and max temperatures. The DateListPlot function layout is fairly simple for easy editing.

londoncoordinates = CityData["London", "Coordinates"];
londonweatherstation = WeatherData[londoncoordinates, "NearestStation"];
sydneycoordinates = CityData["Sydney", "Coordinates"];
sydneyweatherstation = WeatherData[sydneycoordinates, "NearestStation"];

DateListPlot[{
  WeatherData[londonweatherstation, 
   "MaxTemperature", {{2011, 1, 2}, {2012, 1, 2}, "Day"}], 
  WeatherData[londonweatherstation, 
   "MinTemperature", {{2011, 1, 2}, {2012, 1, 2}, "Day"}],
  WeatherData[sydneyweatherstation, 
   "MaxTemperature", {{2011, 1, 2}, {2012, 1, 2}, "Day"}], 
  WeatherData[sydneyweatherstation, 
   "MinTemperature", {{2011, 1, 2}, {2012, 1, 2}, "Day"}]},
  Joined -> True, 
 PlotStyle -> {Hue[0.9, 0.6, 0.6], Hue[0.67, 0.6, 0.6], 
   Hue[0.9, 0.6, 0.6], Hue[0.67, 0.6, 0.6]}, 
 Filling -> {{1 -> {{2}, Lighter[Pink]}}, {3 -> {{4}, Green}}},
 AspectRatio -> 0.5, ImageSize -> 600, 
 FrameTicks -> {{Automatic, Automatic},
   {{"Jan 2011", "Mar 2011", "May 2011", "Jul 2011", "Sep 2011", 
     "Nov 2011", "Jan 2012"}, Automatic}},
 DateTicksFormat -> {"MonthNameShort"},
 FrameLabel -> {{Style["\[Degree]C", Bold, Medium], Null}, {Null, 
    Null}}, RotateLabel -> False,
 PlotLabel -> Row[{Style["Sydney", 22, Bold, Green]
    , "                   ", 
    Style["London", 22, Bold, Lighter[Pink]]}]]

enter image description here

$\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.