Python Bokeh – Visualizing Stock Data
Bokeh can be used to visualize stock market data. Visualization is be done using the
plotting module. Here we will be using the sample stock datasets given to us by Bokeh.
Downloading the dataset :
To download the sample datasets run the following command on the command line :
Alternatively, we can also execute the following Python code :
import bokeh bokeh.sampledata.download()
Analyzing the dataset :
In the sample data provided by Bokeh, there are datasets of the stocks of the following companies :
- AAPL which is Apple
- FB which is Facebook
- GOOG which is Google
- IBM which is International Business Machines
- MSFT which is Microsoft Corporation
All these datasets are available as CSV files. Below is a glimpse into the IBM.csv file :
Date Open High Low Close Volume Adj Close 01-03-2000 102 105.5 100.06 100.25 10807800 84.48 02-03-2000 100.5 105.44 99.5 103.12 11192900 86.9 03-03-2000 107.25 110 106.06 108 10162800 91.01 06-03-2000 109.94 111 101 103.06 10747400 86.85 07-03-2000 106 107 101.69 103 10035100 86.8
The file contains the stock data between the years 2000 and 2013 with over 3000 entries.
Visualizing the Stocks :
We will be plotting a line graph which will track the closing price of the stocks between the years 2000 and 2013 of all the 5 available companies.
- Import the required modules :
- figure, output_file and show from bokeh.plotting
- AAPL, FB, GOOG, IBM and MSFT from bokeh.sampledata.stocks
- Instantiate a figure object with the title and axis types.
- Give the names to x-axis and y-axis.
- Plot line graphs for all the 5 companies.
- Display the model.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course