Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为烧瓶中的绘图/划线对象添加两个Y轴_Python_Plotly_Plotly Dash - Fatal编程技术网

Python 为烧瓶中的绘图/划线对象添加两个Y轴

Python 为烧瓶中的绘图/划线对象添加两个Y轴,python,plotly,plotly-dash,Python,Plotly,Plotly Dash,除了使用烧瓶外,如何创建具有两个y轴的绘图 下面的代码适当地生成了绘图,但我不知道如何添加布局对象 如果使用Plotly根本不可能做到这一点,那么使用Dash是否有一个简单的解决方案?我似乎找不到与链接的Plotly示例等效的破折号示例 xScale = np.linspace(0, 1, len(acoustic_data)) xScale2 = np.linspace(0, 1, len(time_to_failure)) # Create traces acoustic_data = go

除了使用烧瓶外,如何创建具有两个y轴的绘图

下面的代码适当地生成了绘图,但我不知道如何添加布局对象

如果使用Plotly根本不可能做到这一点,那么使用Dash是否有一个简单的解决方案?我似乎找不到与链接的Plotly示例等效的破折号示例

xScale = np.linspace(0, 1, len(acoustic_data))
xScale2 = np.linspace(0, 1, len(time_to_failure))
# Create traces
acoustic_data = go.Scatter(
    x=xScale,
    y=acoustic_data,
    name='acoustic data'
)
time_to_failure = go.Scatter(
    x=xScale2,
    y=time_to_failure,
    name='time to failure',
    # yaxis='y2'
)  
# How do I integrate the layout?
layout = go.Layout(
    title='Earthquick',
    yaxis=dict(
        title='acoustic data'
    ),
    yaxis2=dict(
        title='time to failure',
        overlaying='y',
        side='right'
    )
)
data = [acoustic_data, time_to_failure]
graphJSON = json.dumps(data, cls=plotly.utils.PlotlyJSONEncoder)
return graphJSON

像这样的事情应该能让你达到目的

app=dash.dash()
app.layout=html.Div(style={'backgroundColor':'black'},子级=[
dcc.Graph(id='my-Graph',figure={}),
按钮('updategraph',id='my-Button')
])
@app.callback(输出('my-graph','figure'),
[输入('my-button','n_clicks'))
def更新图表回调(按钮单击:int):
xScale=np.linspace(0,1,len(声学数据))
xScale2=np.linspace(0,1,len(时间到失败))
#创造痕迹
声学数据=去散射(
x=xScale,
y=声学数据,
名称=‘声学数据’
)
失败时间=开始。分散(
x=xScale2,
y=故障发生的时间,
name='time to failure',
#yaxis='y2'
)
#如何整合布局?
布局=开始。布局(
title='Earthquick',
yaxis=dict(
标题:“声学数据”
),
yaxis2=dict(
title='失败时间',
叠加class='y',
右边
)
)
数据=[声学数据,故障时间]
返回开始。图(
数据=数据,
布局=布局)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app.run_服务器(debug=True)

我用一些虚拟数据在本地运行它,它成功了。如果您对此有任何问题,请告诉我。

下面是一个示例,说明如何将示例plotly plot集成到Python Dash中

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[1, 2, 3],
    y=[40, 50, 60],
    name='yaxis data'
)
trace2 = go.Scatter(
    x=[2, 3, 4],
    y=[4, 5, 6],
    name='yaxis2 data',
    yaxis='y2'
)

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                trace1, trace2
            ],
            'layout': go.Layout(
                title='Double Y Axis Example',
                yaxis=dict(
                    title='yaxis title'
                ),
                yaxis2=dict(
                    title='yaxis2 title',
                    titlefont=dict(
                        color='rgb(148, 103, 189)'
                    ),
                    tickfont=dict(
                        color='rgb(148, 103, 189)'
                    ),
                    overlaying='y',
                    side='right'
                )
            )
        }
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)