In [6]:
import numpy as np
import pandas as pd
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import seaborn as sns
from bokeh.charts import Scatter, output_notebook, show
from highcharts import Highchart
from ipywidgets import interact
from IPython.display import HTML,YouTubeVideo
%matplotlib inline
In [7]:
ticker = ['AAPL','MSFT','GOOG']
start = '2017-01-01'#datetime(2016,1,1)
end = '2017-04-30'#datetime(2016,12,31)
df = web.DataReader(ticker,'google',start,end)['Close',:,:]
df
Out[7]:
Youtubeの動画を埋め込めます。
In [ ]:
YouTubeVideo('pYXOF0jziGM')
pandasで簡単にプロットできます。
In [4]:
df[['AAPL','MSFT']].plot()
3次元プロット
In [ ]:
fig3d = plt.figure()
ax3d = fig3d.add_subplot(111,projection='3d')
ax3d.scatter3D(df['AAPL'],df['MSFT'],df['GOOG'])
seabornできれいなプロット
In [ ]:
s = df['AAPL']
sns.set_style('dark')
sns.distplot(s)
In [ ]:
sns.jointplot(x='AAPL',y='GOOG',data=df[['AAPL','GOOG']])
bokeh
In [ ]:
output_notebook()
p = Scatter(data=df,x='AAPL',y='GOOG')#,color='species',legend='top_left')
show(p)
highcharts
In [8]:
options = {
'chart': {
'type': 'scatter',
},
}
H = Highchart()
H.set_dict_options(options)
data = list(zip(df['AAPL'], df['GOOG']))
H.add_data_set(data, 'scatter')
H
Out[8]:
In [9]:
hc=H.buildhtml()
In [10]:
HTML(hc)
Out[10]:
In [11]:
%pwd
Out[11]:
In [12]:
open('test.html', 'w').write(hc)
Out[12]:
In [13]:
import webbrowser
In [14]:
webbrowser.open('test.html')
Out[14]:
In [ ]:
@interact
def plot3d(v1=(0,90,1),v2=(0,90,1)):
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter3D(df['AAPL'],df['GOOG'],df['MSFT'])
ax.set_xlabel("AAPL")
ax.set_ylabel("GOOG")
ax.set_zlabel("MSFT")
ax.view_init(v1,v2)#見る方向を変える
plt.show()
In [ ]: