This chapter focusses on how to do the environmental set up in Python with the help of Plotly.
Installation of Python package
It is always recommended to use Python’s virtual environment feature for installation of a new package. Following command creates a virtual environment in the specified folder.
python -m myenv
To activate the so created virtual environment run activate script in bin sub folder as shown below.
source bin/activate
Now we can install plotly’s Python package as given below using pip utility.
pip install plotly
You may also want to install Jupyter notebook app which is a web based interface to Ipython interpreter.
pip install jupyter notebook
Firstly, you need to create an account on website which is available at https://plot.ly. You can sign up by using the link mentioned herewith https://plot.ly/api_signup and then log in successfully.
Next, obtain the API key from settings page of your dashboard.
Use your username and API key to set up credentials on Python interpreter session.
import plotly plotly.tools.set_credentials_file(username='test', api_key='********************')
A special file named credentials is created in .plotly subfolder under your home directory. It looks similar to the following −
{ "username": "test", "api_key": "********************", "proxy_username": "", "proxy_password": "", "stream_ids": [] }
In order to generate plots, we need to import the following module from plotly package −
import plotly.plotly as py import plotly.graph_objs as go
plotly.plotly module contains the functions that will help us communicate with the Plotly servers. Functions in plotly.graph_objs module generates graph objects