Lesson 21
Plotting in notebooks requires using a magic command, which starts with %
, to initialize the plotting backend.
# Setup
%matplotlib inline
Begin by loading the data in hf.h5. This data set contains high-frequency price data for IBM and MSFT on a single day stored as two Series. IBM is stored as "IBM" in the HDF file, and MSFT is stored as "MSFT.
Problem: Basic Plotting¶
- Plot the
ibm
series which contains the price of IBM. - Add a title and label the axes.
- Add markers and remove the line.
Problem: Subplot¶
Create a 2 by 1 subplot with the price of IBM in the top subplot and the price of MSFT in the bottom subplot.
Problem: Plot with Dates¶
Use matplotlib
to directly plot ibm
against its index
. This is a repeat of a previous plot but shows how to use the plot
command directly.
Exercise: HLOC plot¶
Use the HLOC data to produce a plot of MSFT's 5 minute HLOC where the there are no lines, high is demarcated using a green triangle, low is demarcated using a red downward pointing triangle, open is demarcated using a light grey leftward facing triangle and close is demarcated using a right facing triangle.
Note Get the axes from the first, plot, and reuse this when plotting the other series.
# Setup: Load data and create values
import pandas as pd
msft = pd.read_hdf("data/hf.h5", "MSFT")
msft_5min = msft.resample("300S")
high = msft_5min.max()
low = msft_5min.min()
open = msft_5min.first()
close = msft_5min.last()