Plotly套件
-
我們可以運用Plotly套件來繪製視覺化圖形。
# 匯入numpy套件,為了簡化程式碼,將它套件另外命名成np import numpy as np # 匯入plotly套件,以便繪製視覺化圖形 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot import plotly.graph_objs as go # 建立一個陣列, 在1960與2017的範圍之間建立58個點等分 years = np.linspace(1960, 2017, 58) # 建立一個從0開始,小於58的連續整數陣列,總共58個元素 numbers = np.arange(58) trace = go.Scatter( x = years, y = numbers, mode = 'lines+markers' ) data = [trace] iplot(data, filename='scatter-mode')
我們可以把二種資料繪製到同一個圖形上面。
# 匯入numpy套件,為了簡化程式碼,將它套件另外命名成np import numpy as np # 匯入plotly套件,以便繪製視覺化圖形 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot import plotly.graph_objs as go years = np.linspace(1960, 2017, 58) numbers = np.arange(58) randoms = np.random.randn(58) trace = go.Scatter( x = years, y = numbers, mode = 'lines+markers', name = '序列' ) trace2 = go.Scatter( x = years, y = randoms, mode = 'lines+markers', name = '亂數' ) data = [trace, trace2] iplot(data, filename='scatter-mode')
-