First import numpy and matplotlib
In [ ]:
Copied!
1.1. Create two 2D arrays (xx and yy) representing coordinates x, y on the cartesian plan¶
Both should cover the range (-2, 2) and have 100 points in each direction
In [ ]:
Copied!
1.2. Visualize each 2D array using pcolormesh
¶
Use the correct coordiantes for the x and y axes. Provide axis labels for all of your plots in this assignment.
In [ ]:
Copied!
In [ ]:
Copied!
1.3 From your cartesian coordinates, create polar coordinates $r$ and $\varphi$¶
Refer to the wikipedia page for the conversion formula. You will need to use numpy's arctan2
function. Read its documentation.
In [ ]:
Copied!
1.4. Visualize $r$ and $\varphi$ as functions of $x$ and $y$¶
In [ ]:
Copied!
In [ ]:
Copied!
1.5 Define the function $f = \cos^2(4r) + \sin^2(4\varphi)$ and Plot it as a function of $x$ and $y$¶
In [ ]:
Copied!
In [ ]:
Copied!
1.6 Plot the mean of f with respect to the x axis¶
as a function of y
In [ ]:
Copied!
In [ ]:
Copied!
1.7 Plot the mean of f with respect to the y axis¶
as a function of x
In [ ]:
Copied!
In [ ]:
Copied!
Part II: Making plots with Matplotlib for real data¶
In this problem, we will plot some daily weather data from a NOAA station in Millbrook, NY.
The cell below uses pandas to load the data and populate a bunch of numpy arrays (t_daily_min
, t_daily_max
, etc.)
In [ ]:
Copied!
import pandas as pd
df = pd.read_csv('Millbrook_NY_daily_weather.csv', parse_dates=['LST_DATE'])
df = df.set_index('LST_DATE')
#########################################################
#### BELOW ARE THE VARIABLES YOU SHOULD USE IN THE PLOTS!
#### (numpy arrays)
#### NO PANDAS ALLOWED!
#########################################################
t_daily_min = df.T_DAILY_MIN.values
t_daily_max = df.T_DAILY_MAX.values
t_daily_mean = df.T_DAILY_MEAN.values
p_daily_calc = df.P_DAILY_CALC.values
soil_moisture_5 = df.SOIL_MOISTURE_5_DAILY.values
soil_moisture_10 = df.SOIL_MOISTURE_10_DAILY.values
soil_moisture_20 = df.SOIL_MOISTURE_20_DAILY.values
soil_moisture_50 = df.SOIL_MOISTURE_50_DAILY.values
soil_moisture_100 = df.SOIL_MOISTURE_100_DAILY.values
date = df.index.values
import pandas as pd
df = pd.read_csv('Millbrook_NY_daily_weather.csv', parse_dates=['LST_DATE'])
df = df.set_index('LST_DATE')
#########################################################
#### BELOW ARE THE VARIABLES YOU SHOULD USE IN THE PLOTS!
#### (numpy arrays)
#### NO PANDAS ALLOWED!
#########################################################
t_daily_min = df.T_DAILY_MIN.values
t_daily_max = df.T_DAILY_MAX.values
t_daily_mean = df.T_DAILY_MEAN.values
p_daily_calc = df.P_DAILY_CALC.values
soil_moisture_5 = df.SOIL_MOISTURE_5_DAILY.values
soil_moisture_10 = df.SOIL_MOISTURE_10_DAILY.values
soil_moisture_20 = df.SOIL_MOISTURE_20_DAILY.values
soil_moisture_50 = df.SOIL_MOISTURE_50_DAILY.values
soil_moisture_100 = df.SOIL_MOISTURE_100_DAILY.values
date = df.index.values
2.1 Use numpy to calculate mean temperature, precipitation and soil moisture at different layers.¶
Write a loop to make the code short and efficient.
In [ ]:
Copied!
In [ ]:
Copied!
2.2 Use the numpy arrays to try to re-create the plot you see below¶
Hint: Try fill_between to plot range values
In [7]:
Copied!
In [ ]:
Copied!
In [ ]:
Copied!