{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
drop
method to remove the now unused columns for year,\n",
" month, day, hour, and minute (HINT: Look at the axis
keyword\n",
" argument in the documentation).df[COLUMN_NAME].shift(OFFSET)
returns the values of COLUMN_NAME shifted by OFFSET). inplace
keyword argument. This allows us to modify the dataframe without continually needing to reassign it. df = df.command(...)
becomes df.command(..., inplace=True)
.\n",
"\n",
"\n",
"# Using inplace means the return is None and the dataframe is simply modified.\n",
"df.drop(['year', 'month', 'day', 'hour', 'minute'], axis='columns', inplace=True)\n",
"\n",
"# BONUS: add a column for intervals between observations\n",
"df['duration'] = df['time'] - df['time'].shift(-1)\n",
"\n",
"df.head()\n",
"
\n",
"myfig, myax = plt.subplots(figsize=(10, 6))
) which plots temperature.linestyle
, e.g., a blue dashed line.\n",
"myfig, myax = plt.subplots(figsize=(10, 6))\n",
"\n",
"# Plot temperature\n",
"myax.plot(df.time, df.temperature, color='tab:blue', linestyle='-.', label='Temperature')\n",
"\n",
"myax.set_xlabel('Time')\n",
"myax.set_ylabel('Temperature (degC)')\n",
"myax.set_title('Buoy 41056 Data')\n",
"myax.grid(True)\n",
"\n",
"# format x axis labels\n",
"myax.xaxis.set_major_locator(DayLocator())\n",
"myax.xaxis.set_major_formatter(DateFormatter('%b %d'))\n",
"\n",
"myax.legend(loc='upper left');\n",
"fig\n",
"
\n",
"\n",
"myfig, myax = plt.subplots(figsize=(10, 6))\n",
"myaxb = myax.twinx()\n",
"\n",
"# Same as above\n",
"myax.set_xlabel('Time')\n",
"myax.set_ylabel('Wave Height (m)')\n",
"myax.set_title('Buoy 41056 Data')\n",
"myax.grid(True)\n",
"\n",
"# Plotting on the first y-axis\n",
"myax.plot(df.time, df.wave_height, color='tab:blue', label='Waveheight (m)',\n",
" linestyle='None', marker='o')\n",
"\n",
"# Plotting on the second y-axis\n",
"myaxb.set_ylabel('Windspeed (m/s)')\n",
"myaxb.plot(df.time, df.wind_speed, color='tab:green', label='Windspeed (m/s)')\n",
"\n",
"myax.xaxis.set_major_locator(DayLocator())\n",
"myax.xaxis.set_major_formatter(DateFormatter('%b %d'))\n",
"\n",
"# Handling of getting lines and labels from all axes for a single legend\n",
"mylines, labels = myax.get_legend_handles_labels()\n",
"mylines2, labels2 = myaxb.get_legend_handles_labels()\n",
"myax.legend(lines + lines2, labels + labels2, loc='upper left');\n",
"
\n",
"