Python向X和Y轴破折号应用程序添加标题

时间:2019-06-13 14:39:45

标签: python plotly plotly-dash

我正在尝试创建一个破折号应用程序,以创建一些数据的散点图。有人能给我一个提示,以在图的x和y轴上显示标题吗?我在网上找到的大多数文档似乎都适用于IPython。布局以以下格式定义:

layout = dict(
        title= 'Rank',
        ticklen= 5,
        gridwidth= 2,
    )

但是我的破折号应用程序看起来更像这种格式: 编辑以在下面包含所有代码

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
import numpy as np

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

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



df = pd.read_csv('boilerData.csv', index_col='Date', parse_dates=True)
df = df.fillna(method = 'ffill').fillna(method = 'bfill')

app.layout = html.Div([

    html.H1('Heating System Temperature Data Visulation'), 
    html.Center('The purpose of the scatter plot below is to prove if a temperature reset strategy is implemented on the hydronic heating system. At various outside air temperature conditions, the hot water temperature should fluctuate to save energy.'),

    dcc.Graph(
        id='hwst-vs-oat',
        figure={
            'data': [
                go.Scatter(
                    x = df.OAT,
                    y = df.HWST,
                    mode = 'markers',
                    marker = dict(
                        color = '#FFBAD2',
                        line = dict(width = 1)
                    )
                )
            ],
            'layout':{
            'title':'Scatter Plot of OAT versus HWST',
            'xaxis':{
                'title':'whatever you want x to be'
            },
            'yaxis':{
                 'title':'whatever you want y to be'
            }
        }
    )
])


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

任何提示都可以帮助您。

1 个答案:

答案 0 :(得分:0)

应该能够做这样的事情

import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
import plotly.graph_objs as go
import numpy as np

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

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



df = pd.read_csv('boilerData.csv', index_col='Date', parse_dates=True)
df = df.fillna(method = 'ffill').fillna(method = 'bfill')


app.layout = html.Div([

    html.H1('Heating System Temperature Data Visulation'), 
    html.Center('The purpose of the scatter plot below is to prove if a temperature reset strategy is implemented on the hydronic heating system. At various outside air temperature conditions, the hot water temperature should fluctuate to save energy.'),

    dcc.Graph(
        id='hwst-vs-oat',
        figure={
            'data': [
                go.Scatter(
                    x = df.OAT,
                    y = df.HWST,
                    mode = 'markers',
                    marker = dict(
                        color = '#FFBAD2',
                        line = dict(width = 1)
                    )
                )
            ],
            'layout':{
                'title':'Scatter Plot of OAT versus HWST',
                'xaxis':{
                    'title':'whatever you want x to be'
                },
                'yaxis':{
                    'title':'whatever you want y to be'
                }
            }
        }  
    )
])

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