Code
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
β¬ οΈ Previous Session | π Course Home
Donβt forget to start your notebook with a cell containing the import statements you need for the session.
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
Recreate the plot below. You do not need to match the colors exactly, but do not rely on matplotlib defaults. Note: do not worry about the equation(s); these are included to indicate which functions to plot.
import numpy as np
import matplotlib.pyplot as plt
# Generate x values from 0.1 to 100 (avoiding x=0, which is undefined for log(x))
= np.linspace(0.1, 100, 1000)
x
# Calculate y values using the logarithmic function
= np.log(x)
y
# Create the plot
=(8, 6))
plt.figure(figsize='y = log(x)', color=(19/255,121/255,112/255))
plt.plot(x, y, label'x')
plt.xlabel('y')
plt.ylabel('Plot of y = log(x)')
plt.title(False)
plt.grid(#plt.legend()
0, 100)
plt.xlim(-2, 5) # Adjust the y-axis limits as needed
plt.ylim( plt.show()
Recreate the plot below. You do not need to match the colors exactly, but do not rely on matplotlib defaults. Note: do not worry about the equation(s); these are included to indicate which functions to plot.
# Generate x values from 0 to 10
= np.linspace(0, 10, 1000)
x
# Define values of A
= [1, 5, 10]
A_values
# Create subplots for each value of A
=(12, 8))
plt.figure(figsize
for A in A_values:
= A * x * np.sin(2 * np.pi * x)
y =f'A = {A}')
plt.plot(x, y, label
'x')
plt.xlabel('y')
plt.ylabel('Plot of y = A*x*sin(2*pi*x) for Different Values of A')
plt.title(True)
plt.grid(
plt.legend()0, 10)
plt.xlim(-100, 100) # Adjust the y-axis limits as needed
plt.ylim( plt.show()
Import the data from ./data/BSRN_data.csv
and plot the temperature and relative humidity over the month of October 2019 at the BSRN station. Be sure to format the timestamps and include axis labels, a title, and a legend, if necessary.
import pandas as pd
import matplotlib.pyplot as plt
# Load your data
= pd.read_csv('../data/BSRN_GOB_2019-10.csv', index_col=0, parse_dates=True)
df
# Create a figure with two y-axes
= plt.subplots(figsize=(10, 6))
fig, ax1
# Plot temperature data on the left y-axis (ax1)
'T_degC'], color='tab:blue', label='Temp deg-C')
ax1.plot(df.index, df['Date')
ax1.set_xlabel('Temp deg-C', color='tab:blue')
ax1.set_ylabel(='y', labelcolor='tab:blue')
ax1.tick_params(axisTrue)
ax1.grid(='upper left')
ax1.legend(loc
# Create a second y-axis on the right for RH data
= ax1.twinx()
ax2 'RH'], color='tab:red', label='RH')
ax2.plot(df.index, df['RH', color='tab:red')
ax2.set_ylabel(='y', labelcolor='tab:red')
ax2.tick_params(axis='upper right')
ax2.legend(loc
'Temperature and Relative Humidity Over Time')
plt.title( plt.show()
Saturation vapor pressure, ( $ e^*(T_a) $ ), is the maximum pressure of water vapor that can exist in equilibrium above a flat plane of water at a given temperature. It can be calculated from the Tetens equation:
e^{*}(T_{a}) = a \times exp({\frac{b \cdot T_{a}}{T_{a} + c}})
where $ T_a $ is the air temperature in Β°C, $ a = 0.611 $ kPa, $ b = 17.502 $, and $ c = 240.97 Β°C $.
bsrn
.The difference between saturation vapor pressure and ambient air pressure is called vapor pressure deficit, \textit{VPD}. \textit{VPD} can be calculated from saturation vapor pressure and relative humidity, h_r, as follows: \textit{VPD} \, = \, e^*(T_a) \cdot (1 \, - \, h_r) where h_r is expressed as a fraction.