2016-12-14 11 views
0

私は二重グラフを作成する必要があります。基本的に、1つのグラフには「通常の」プロットがあります。これは、言い換えれば、キリンの価格です。他のプロットは、当時所有していたキリンの量に基づいています。番号に基づく背景の陰影特定部分

他のプロットは、それに応じてプロットの背景を陰影付けすることによって表現する必要があります。

enter image description here どのように影付きグラフを作成するのですか?

ありがとうございます!

答えて

0

Plotlyのshapeをレイアウト設定で使用できます。

enter image description here

import plotly 
import time 
import random 
import datetime 

#create some random input data 
N = 100 

starttime = time.time() 
x = [datetime.date.fromtimestamp(starttime - 60*60*24*N).strftime('%Y-%m-%d')] 
y = [10] 
for i in range(N): 
    x.append(datetime.date.fromtimestamp(starttime - 60*60*24*N + i*60*60*24).strftime('%Y-%m-%d')) 
    y.append(abs(y[-1] + random.randint(-7, 5 + int(N/25)))) 

trace = plotly.graph_objs.Scatter(
    x = x, 
    y = y, 
    mode='line', 
) 

layout = dict(shapes = list()) 
#highlight the minimum in red 
layout['shapes'].append(
    { 
     'type': 'rect', 
     'xref': 'x', 
     'yref': 'paper', 
     'x0': trace.x[trace.y.index(min(trace.y)) - 5], 
     'y0': 0, 
     'x1': trace.x[trace.y.index(min(trace.y)) + 5], 
     'y1': max(trace.y), 
     'fillcolor': '#ff0000', 
     'opacity': 0.2, 
     'line': { 
      'width': 0, 
     } 
    } 
) 

#highlight the maximum in green 
layout['shapes'].append(
    { 
     'type': 'rect', 
     'xref': 'x', 
     'yref': 'paper', 
     'x0': trace.x[trace.y.index(max(trace.y)) - 5], 
     'y0': 0, 
     'x1': trace.x[(trace.y.index(max(trace.y)) + 5) - ((trace.y.index(max(trace.y)) + 6) % len(trace.y))], 
     'y1': max(trace.y), 
     'fillcolor': '#00ff00', 
     'opacity': 0.2, 
     'line': { 
      'width': 0, 
     } 
    } 
) 

fig = dict(data=[trace], layout=layout) 
plotly.plotly.sign_in('user', 'token') 
plot_url = plotly.plotly.plot(fig) 
関連する問題