Plotly Installation
To install Plotly's Python Package on Ubuntu Linux (it is straightforward to install on other operating systems), open the command line and follow the procedures below:
- $ pip install plotly
- or
- $ sudo pip install plotly
- #Plotly's Python package is updated frequently! To upgrade, run:
- $ pip install plotly --upgrade
Plotly provides a web-service for hosting graphs you generate! You can create a free account to be able to save your graphs inside your online Plotly account and decide how you control the privacy. Public hosting is free.
To initialize Plotly for online plotting and graph hosting, open the command line and follow the steps below:
- #Invoke Python/Ipython interpreter
- $python
- #Import plotly and set your credentials:
- import plotly.tools as tls
- tls.set_credentials_file(username='Your_Account_Name', api_key='API_Key') #Insert Your_Account_Name and API_Key, use our account name TSSFL and API Key: VIrC8tjxOn2nwujbiwrk for demo
The initialization step places a special .plotly/ credentials file in your home directory, which should look something like this:
- {
- "username": "Your_Account_Name",
- "stream_ids": ["ylosqsyet5", "h2ct8btk1s", "oxz4fm883b"],
- "api_key": "lr1c37zw81"
- }
We create a simple Python program to plot and automatically upload the graph to our public Plotly account: https://plot.ly/~TSSFL
- """Plotly Demo"""
- import numpy as np
- import matplotlib.pyplot as plt
- import plotly.plotly as py
- graph = plt.figure()
- data = np.loadtxt("gals-DR123b_t1.txt", skiprows=3)
- number_of_colums = len(data[:,0]) #196237
- number_of_rows = len(data[0,:]) #42
- C5 = data[:,0:5] #From first to fifth columns
- C15 = data[:,10:15] #From eleventh to fifteenth columns
- fb1 = C5[:,2] #First frequency band in C5
- fb2 = C15[:,2] #First frequency band in C15
- eccentricity = fb2/fb1
- #Plot histogram
- bins = 50
- eccentricity = eccentricity[eccentricity<1.0]
- plt.hist(eccentricity[~np.isnan(eccentricity)], bins, normed=False, facecolor='green', alpha=.5) #Get rid of 'NAN', you can use bins = 'auto'
- plt.xlabel('Epsilon')
- plt.ylabel('Number of Galaxies')
- plt.title("Histogram")
- plot_url = py.plot_mpl(graph, filename='Test_Plotly.png')
Code: Select all
plot_url = py.plot_mpl(graph, filename='Test_Plotly.png')
Currently, plotly provides libraries for:
Scala
ggplot2
R
JS plotly.js
Python
Pandas
node.js
Matplotlib
MATLAB