繁体   English   中英

未显示 y 轴的 Plotly/Dash 标题

[英]Plotly/Dash title of y-axes are not shown

我想用 Plotly/Dash 创建一个仪表板。 如果我只是 plot 我的数字与figDashboard.show()一切都很好。 但是创建仪表板

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='Cake Lapis Dashboard',
        style={
            'textAlign': 'center'
        }
    ),
    html.Div(children='Graphical representation of pool transactions (Lapis entries)', style={
        'textAlign': 'center'
    }),
    dcc.Graph(
        id='Graph1',
        figure=figDashboard
    )
])

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

未显示子图中轴的标题,我不知道为什么。 这是创建图形和子图的代码

figDashboard = make_subplots(
    rows=2, cols=2,
    vertical_spacing=0.0,
    horizontal_spacing = 0.25,
    row_width=[0.5, 0.5], # from bottom to top
    specs=[[{"type": "table","rowspan":2},{}],
          [None,{}]],
    shared_xaxes = True)

# Subplot for transaction entries (fees and gross return)
trace_GrossReturn = dict(type='bar',name='Gross return',x=aData.index, y=aData['GrossReturn'])
trace_EntryFee = dict(type='bar',name='Entry fee',x=aData.index, y=aData['EntryFee'])
trace_AddFee = dict(type='bar',name='Additional service fee',x=aData.index, y=aData['AdditionalFee'])
figDashboard.add_trace(trace_GrossReturn,1,2)
figDashboard.add_trace(trace_EntryFee,1,2)
figDashboard.add_trace(trace_AddFee,1,2)

figDashboard.update_yaxes(title_text="Transactions in BTC",ticks='',tickformat=".8f", range=[0, 0.0003], row=1, col=2)

figDashboard.update_layout(
    barmode='stack',
    height=800,
    showlegend=False,
    title_text="Cashflow",
    yaxis=dict(title='Crude and Model'),
)

我希望你们中的某个人可以帮助我。 我不知道,有什么问题。

今天我也创建了一个小例子,它完全可以运行(我已经删除了所有不需要的代码并在里面放了一些示例数据)

import pandas as pd
import plotly.io as pio
from plotly.subplots import make_subplots

import dash
import dash_core_components as dcc
import dash_html_components as html

pio.renderers.default = "browser"



Data = pd.DataFrame(index=[1, 2, 3, 4, 5])
Data['y1'] = [2.0, 3.0, 4.0, 3.0, 2.0]
Data['y1'] = Data['y1']*0.0001
Data['y2'] = Data['y1']*3
Data['y3'] = Data['y1']*0.8


figDashboard = make_subplots(
    rows=2, cols=2,
    vertical_spacing=0.0,
    horizontal_spacing = 0.25,
    row_width=[0.5, 0.5], # from bottom to top
    specs=[[{"type": "table","rowspan":2},{}],
          [None,{}]],
    shared_xaxes = True)

# Subplot for transaction entries (fees and gross return)
trace_GrossReturn = dict(type='bar',name='Data1',x=Data.index, y=Data['y1'])
trace_EntryFee = dict(type='bar',name='Data2',x=Data.index, y=Data['y2'])
trace_AddFee = dict(type='bar',name='Data3',x=Data.index, y=Data['y3'])
figDashboard.add_trace(trace_GrossReturn,1,2)
figDashboard.add_trace(trace_EntryFee,1,2)
figDashboard.add_trace(trace_AddFee,1,2)


# Subplot for net return in coin and fiat
trace_netReturn = dict(type='scatter',name='Data1',x=Data.index, y=Data['y1'],
                       mode='lines',fill='tozeroy',line=dict(color='blue'),fillcolor='rgba(0, 0, 255, 0.2)')
figDashboard.add_trace(trace_netReturn,2,2)

figDashboard.update_yaxes(title_text="Title of first y-axis",ticks='',tickformat=".8f",row=1, col=2)
figDashboard.update_yaxes(title_text='Title second y-axis',showgrid=False, tickformat=".8f", row=2, col=2)

figDashboard.update_xaxes(title_text="Title x-axis ", row=2, col=2)

figDashboard.update_layout(
    barmode='stack',
    height=800,
    showlegend=False,
    margin=dict(t=50),
)


#figDashboard.show()

app = dash.Dash(__name__)

app.layout = html.Div(children=[
    html.H1(
        children='Dashboard',
        style={
            'textAlign': 'center'
        }
    ),
    html.Div(children='Testframe for y-axes labeling', style={
        'textAlign': 'center'
    }),
    dcc.Graph(
        id='Graph1',
        figure=figDashboard
    )
])

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

我现在在另一台机器上尝试了代码,它在那里工作,真的很奇怪。 工作机上有一个不同的控制台output,即

127.0.0.1 - - [02/Jul/2020 08:15:55] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_renderer/react@16.v1_5_1m1593669821.13.0.min.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_renderer/prop-types@15.v1_5_1m1593669821.7.2.min.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_renderer/polyfill@7.v1_5_1m1593669821.8.7.min.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_html_components/dash_html_components.v1_0_3m1593669825.min.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_renderer/react-dom@16.v1_5_1m1593669821.13.0.min.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_core_components/dash_core_components-shared.v1_10_1m1593669823.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_core_components/dash_core_components.v1_10_1m1593669823.min.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-component-suites/dash_renderer/dash_renderer.v1_5_1m1593669821.min.js HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_dash-dependencies HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:15:55] "GET /_favicon.ico?v=1.13.4 HTTP/1.1" 200 -

在不工作的机器上,我只得到了这个 output

127.0.0.1 - - [02/Jul/2020 08:19:29] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:19:30] "GET /_dash-layout HTTP/1.1" 200 -
127.0.0.1 - - [02/Jul/2020 08:19:30] "GET /_dash-dependencies HTTP/1.1" 200 -

所以,对我来说,似乎缺少一些东西,但所有软件包都已安装,我还重新启动了 kernel。

经过漫长的搜索之旅,我发现了问题所在。 在不工作的机器上,安装了一个非常旧的破折号版本(0.21.1)。 对于 package 安装,我使用pip install dash 不知道,为什么要安装旧版本。 使用pip install dash==1.13.4 (版本已安装在工作机器上)我得到了更新的版本,现在它可以工作了。 也许这个答案可以帮助另一个人;-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM