Visualize Seasonal Patterns
Compare seasonal precipitation in a Midwest and a Southwest location.
WeatherData provides aggregated precipitation in cm.
In[1]:=
start = {1999, 1, 1};
end = {2015, 12, 31};
In[2]:=
getData[place_] :=
WeatherData[place, "TotalPrecipitation", {start, end, "Month"}]
Create a TimeSeries of precipitation for Champaign, IL, and Phoenix, AZ. Specify MissingDataMethod to use interpolation to fill in missing data.
In[3]:=
makeTS[place_] :=
TimeSeries[getData[place], MissingDataMethod -> "Interpolation"]
In[4]:=
tsIL = makeTS[
Entity["City", {"Champaign", "Illinois", "UnitedStates"}]]
Out[4]=
In[5]:=
tsAZ = makeTS[Entity["City", {"Phoenix", "Arizona", "UnitedStates"}]]
Out[5]=
Create WeightedData with amounts of precipitation as weights and plot DateHistogram averaging the data over the total number of years.
In[6]:=
dataIL = WeightedData[tsIL["Dates"], tsIL["Values"]];
dataAZ = WeightedData[tsAZ["Dates"], tsAZ["Values"]];
In[7]:=
totalyears = (end[[1]] - start[[1]] + 1);
In[8]:=
avg := Function[{x, y}, y/totalyears]
In[9]:=
makeHistogram[data_, lab_] :=
DateHistogram[data, "Month", avg, DateReduction -> "Year",
PlotRange -> {All, {-1, 9}}, AxesLabel -> "cm", PlotLabel -> lab]
In[10]:=
{makeHistogram[dataIL, "IL"], makeHistogram[dataAZ, "AZ"]}
Out[10]=