本文实例讲述了python基于plotly模块实现的画图操作。分享给大家供大家参考,具体如下:
1
2
|
import plotly plotly.tools.set_credentials_file(username = 'tianjixuetu' , api_key = 'xxxxxxxx' ) #此处要去官网申请自己的api,#https://plot.ly/ssu/ |
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#案例1 import plotly.plotly as py from plotly.graph_objs import * trace0 = scatter( x = [ 1 , 2 , 3 , 4 ], y = [ 10 , 15 , 13 , 17 ] ) trace1 = scatter( x = [ 1 , 2 , 3 , 4 ], y = [ 16 , 5 , 11 , 9 ] ) data = data([trace0, trace1]) py.plot(data, filename = 'basic-line' ) |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#案例2 import plotly.graph_objs as go import plotly.plotly as py import numpy as np colorscale = [[ 0 , '#faee1c' ], [ 0.33 , '#f3558e' ], [ 0.66 , '#9c1de7' ], [ 1 , '#581b98' ]] trace1 = go.scatter( y = np.random.randn( 500 ), mode = 'markers' , marker = dict ( size = '16' , color = np.random.randn( 500 ), colorscale = colorscale, showscale = true ) ) data = [trace1] url_1 = py.plot(data, filename = 'scatter-for-dashboard' , auto_open = false) py.iplot(data, filename = 'scatter-for-dashboard' ) url_1 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#案例3 import plotly.plotly as py import plotly.graph_objs as go import numpy as np x0 = np.random.randn( 50 ) x1 = np.random.randn( 50 ) + 2 x2 = np.random.randn( 50 ) + 4 x3 = np.random.randn( 50 ) + 6 colors = [ '#faee1c' , '#f3558e' , '#9c1de7' , '#581b98' ] trace0 = go.box(x = x0, marker = { 'color' : colors[ 0 ]}) trace1 = go.box(x = x1, marker = { 'color' : colors[ 1 ]}) trace2 = go.box(x = x2, marker = { 'color' : colors[ 2 ]}) trace3 = go.box(x = x3, marker = { 'color' : colors[ 3 ]}) data = [trace0, trace1, trace2, trace3] url_2 = py.plot(data, filename = 'box-plots-for-dashboard' , sharing = 'public' , auto_open = true,world_readable = true) py.iplot(data, filename = 'box-plots-for-dashboard' ) url_2 |
希望本文所述对大家python程序设计有所帮助。
原文链接:https://blog.csdn.net/qq_26948675/article/details/77876846