plotly系列(2)-- 多子图绘制功能

同matplotlib一样,plotly的一个画布对象也可以包含多个子图。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
x=[1, 2, 3],
y=[4, 5, 6]
)
trace2 = go.Scatter(
x=[20, 30, 40],
y=[50, 60, 70],
xaxis='x2',
yaxis='y2'
)
trace3 = go.Scatter(
x=[300, 400, 500],
y=[600, 700, 800],
xaxis='x3',
yaxis='y3'
)
trace4 = go.Scatter(
x=[4000, 5000, 6000],
y=[7000, 8000, 9000],
xaxis='x4',
yaxis='y4'
)
data = [trace1, trace2, trace3, trace4]

layout = go.Layout(
xaxis=dict(
domain=[0, 0.45]
),
yaxis=dict(
domain=[0, 0.45]
),
xaxis2=dict(
domain=[0.55, 1]
),
xaxis3=dict(
domain=[0, 0.45],
anchor='y3'
),
xaxis4=dict(
domain=[0.55, 1],
anchor='y4'
),
yaxis2=dict(
domain=[0, 0.45],
anchor='x2'
),
yaxis3=dict(
domain=[0.55, 1]
),
yaxis4=dict(
domain=[0.55, 1],
anchor='x4'
)
)

fig = go.Figure(data=data, layout=layout)

py.offline.plot(fig, filename='multiple-subplots.html', auto_open=True)
0%