首页 > 解决方案 > Python为x和y轴破折号应用程序添加标题

问题描述

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

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

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

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)

任何提示都有帮助,谢谢。

标签: pythonplotlyplotly-dash

解决方案


应该能够做这样的事情

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)

推荐阅读