简体   繁体   中英

Plotly/Dash title of y-axes are not shown

I want to create a dashboard with Plotly/Dash. If I just plot my figure with figDashboard.show() everything is fine. But creating the Dashboard with

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) 

the title of the axes in the subplots are not shown and I don't know why. Here is the code of creating the figure and subplots

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'),
)

I hope someone of you can help me. I have no idea, what is wrong.

Today I have also create a small example, which is completely runnable (I have delete every unneeded code and put some example data inside)

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)

I now tried the code on a separate machine and there it works, really strange. There is a different console output on the working machine, which is

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 -

On the not working machine I only got this 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 -

So, for me it looks like something is missing, but all packages are installed and I have also restarted the kernel.

After a long search journey, I found the problem. On the not working machine, there was a really old dash version (0.21.1) installed. For package installation I used pip install dash . No idea, why the old version was installed. With pip install dash==1.13.4 (version was installed on the working machine) I got the newer version and now it works. Maybe this answer help another person;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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