【问题标题】:How to hide labels per default in a python dash graph?如何在 python 破折号图中默认隐藏标签?
【发布时间】:2018-12-04 23:42:29
【问题描述】:

假设我有一个这样的简单图表:

import dash
import dash_core_components as dcc
import dash_html_components as html

app = dash.Dash()

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    )
])

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

代码生成以下图表:

如果我点击“SF”或“Montréal”这两个标签之一,这个特定标签会变灰并从图表中移除。有没有办法默认将标签变灰?我想绘制一个带有很多标签的图表,但它看起来很乱。但我也不想排除任何数据。实现干净外观但同时保持数据完整性的一个好方法是默认隐藏这些标签。提前致谢

【问题讨论】:

    标签: python dashboard plotly-dash


    【解决方案1】:

    这在plotly中很容易实现。

    您必须将'visible': 'legendonly' 添加到您的跟踪中。

    例子:

    'data': [
            {'x': [1, 2, 3],
             'y': [4, 1, 2],
             'type': 'bar',
             'name': 'SF',
             'visible': 'legendonly'
             },
            {'x': [1, 2, 3],
             'y': [2, 4, 5],
             'type': 'bar',
             'name': u'Montréal'
             },
        ],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-25
      • 1970-01-01
      • 2011-08-30
      • 2012-03-09
      • 1970-01-01
      相关资源
      最近更新 更多