This article is a 12/18 minute post of jupyter notebook Advent Calender 2016.
The author is a beginner of Jupyter notebook. Not bad.
This time, I will introduce a simple procedure to use plotly on jupyter notebook.
plotly is a data visualization platform. You can edit and share various graphs online. You can draw more stylish graphs than Matplotlib. I said online, but of course you can use it locally. (It seems that it couldn't be done in the past!) Basically, all functions are available for free. By the way, there seems to be a company developing in Montreal, Canada.
It can also be used in conjunction with languages such as Rython and R, Matlab, JavaScript, Ruby, Go ..., and hardware such as Arduino and Rasberry Pi.
It seems that some functions such as 3D plotting have been charged in the past, but these became free as a result of being open sourced around the end of last year. You did it.
Although I felt it was very convenient even though I was an amateur, it seems that it is not very popular in Japan (?).
So far, I've written that, about a similar service Bokeh, driller is already firmly in the Advent Calender of the day before yesterday. It was put together.
Use ipywidgets and Bokeh for interactive visualization
As an aside, Continuum Analysis, famous for Anaconda, is mainly developing Bokeh, while the recently talked about Exploratory. Due to the influence of R-based software called .io /)
It seems that the composition of is being made. (I'm sorry if it's different.)
① At the terminal or command prompt
$ pip install plotly
Or if you have anaconda installed
$ conda install plotly
To install the Plotly Python package.
If it is already installed, upgrade accordingly.
② Log in from the plotly site. If you don't have an account, sign up. As of December 2016, you can sign up on facebook, Google+, Twitter, and GitHub.
③ After signing up safely, you will receive a confirmation email from [email protected], so check it.
④ Check your API key from Setting on the user page.
⑤ If necessary, set the credentials file (authentication file).
On Jupyter notebook
plotly.tools.set_credentials_file(username="xxxxxxx", api_key="yyyyyyy"
To execute.
(Every time you run Plotly without doing this
py = plotly.plotly(username='<your-username>', key='<your-api-key>')
You can also write as. )
This completes the preparation.
import plotly
plotly.__version__
>>> 1.12.9
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.tools import FigureFactory as FF
import pandas as pd
import numpy as np
import string
x1 = np.random.randn(100)-2
x2 = np.random.randn(100)
x3 = np.random.randn(100)+2
hist_data = [x1, x2, x3]
group_labels = ['Shibuya', 'Shinagawa', 'Shinjuku']
colors = ['rgb(50, 0, 200)', 'rgb(200, 50, 0)','rgb(0, 200, 50)']
fig = FF.create_distplot(hist_data, group_labels,colors=colors, bin_size=.1)
py.iplot(fig, filename='Compare with 3 city', validate=False)
https://plot.ly/~Tearon/32
N = 100
y_vals = {}
for letter in list(string.ascii_uppercase):
y_vals[letter] = np.random.randn(N)+(3*np.random.randn())
df = pd.DataFrame(y_vals)
data = []
for col in df.columns:
data.append( go.Box( y=df[col], name=col, showlegend=False ) )
data.append( go.Scatter( x = df.columns, y = df.mean(), mode='lines', name='mean line' ) )
py.iplot(data, filename='pandas-box-plot', validate=False)
https://plot.ly/~Tearon/30
There is an Official Cheat Sheet so you can see the simple grammar here.
How was that. I was only able to show you a very simple graph this time, but you can see that various interactive drawings are possible just by looking at the official website. If you are interested, please try it.
Recommended Posts