绘制条形图轴

发布于 2025-02-05 08:39:49 字数 1172 浏览 3 评论 0原文

我试图创建一个简单的条形图并将其部署在下拉菜单中。我的问题是轴。我不知道为什么当我使用px.bar时部署时只需采用一个变量(x或y)并制作绘图,但是当我使用px时,它可以使用,它可以使用两个变量。

from dash import Dash, dcc, html, Input, Output 
import plotly.express as px
import pandas as pd
import numpy as np

app = Dash(__name__)

pf = fr.iloc[2:10,18:25]
pf.columns = [prueba1]
pf.index = ['CH + CHL','CH','CHL(UST)','CHL','CL + CHL','CL','CHL(UST)','CHL']


app.layout = html.Div(children=[
html.Div([dcc.Dropdown(pf.index,'CH', id='pandas-dropdown-2'),
html.Div(id='pandas-output-container')]),

dcc.Graph(id='example-graph')
])
Output('example-graph','figure'),
Input('pandas-dropdown-2', 'value'))


def update_graph(value_input):
    pff = pf[pf.index == value_input]
    fig = px.bar(pff, x = np.array(prueba1), y = list(pff.values))#,
return fig

__name__ == '__main__':
app.run_server(debug=True, use_reloader=False)

结果是:

在此处输入图像描述

为什么y标签是数字而不是年数?

但是,当我从px.bar更改为px。扫描发生:

在此处输入图像说明

作品!!!但是我需要条形图!

Im trying to create a simple bar chart and deploy it within a dropdown menu. My problem is with the axes. I do not know why when I use px.bar the deploy just take one variable (x or y) and make the plot, but when I use px.scatter it works, it takes both variables.

from dash import Dash, dcc, html, Input, Output 
import plotly.express as px
import pandas as pd
import numpy as np

app = Dash(__name__)

pf = fr.iloc[2:10,18:25]
pf.columns = [prueba1]
pf.index = ['CH + CHL','CH','CHL(UST)','CHL','CL + CHL','CL','CHL(UST)','CHL']


app.layout = html.Div(children=[
html.Div([dcc.Dropdown(pf.index,'CH', id='pandas-dropdown-2'),
html.Div(id='pandas-output-container')]),

dcc.Graph(id='example-graph')
])
Output('example-graph','figure'),
Input('pandas-dropdown-2', 'value'))


def update_graph(value_input):
    pff = pf[pf.index == value_input]
    fig = px.bar(pff, x = np.array(prueba1), y = list(pff.values))#,
return fig

__name__ == '__main__':
app.run_server(debug=True, use_reloader=False)

The result is this one:

enter image description here

Why the Y label is count instead of years?

But when I change from px.bar to px.scatter this happens:

enter image description here

It works!!! But I need the bar chart!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文