未显示雅克斯的绘图/破折号标题

2024-10-01 17:25:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用Plotly/Dash创建一个仪表板。如果我只是画出我的数字 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)

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

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 -

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

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 -

所以,对我来说,它似乎缺少一些东西,但所有的软件包都已安装,我也重新启动了内核


Tags: namehttpdatagetindexhtmltypetrace
1条回答
网友
1楼 · 发布于 2024-10-01 17:25:10

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

相关问题 更多 >

    热门问题