绘图-如何突出显示同一绘图中两个图形的两个结果

时间:2018-10-22 12:50:41

标签: python python-3.x plotly

我在Python版本3中使用了plotly,并且有一个图,其中有两行是不同的图形,例如picture。我想同时用鼠标突出显示上下图中的两个值!我的代码如下:

trace0 = go.Scatter(
    x=df.date,
    y=df.price,
    name='Volume',
    line=dict(
        color='rgb(205, 12, 24)',
        width=4)
)

trace1 = go.Scatter(
    x=df.date,
    y=df.sentiment,
    name='Sentiment',
    mode='lines+markers',
    line=dict(
        color='rgb(22, 96, 167)',
        width=4)
)

fig = tools.make_subplots(rows=2, cols=1)

fig.append_trace(trace0, 1, 1)
fig.append_trace(trace1, 2, 1)

fig['layout'].update(height=600, width=800, title='Sentiment Analysis on Social Media')
py.plot(fig, filename='simple-subplot-with-annotations')

1 个答案:

答案 0 :(得分:0)

用以下内容替换“ fig = tools.make_subplots(rows = 2,cols = 1)”

import plotly.offline as py
import plotly.graph_objs as go    
data = [trace0, trace1]  
layout = go.Layout(
    title = 'Sentiment Analysis on Social Media')
fig = go.Figure(data=data,layout=layout)
py.plot(fig, filename='simple-subplot-with-annotations.html')
相关问题