我有一本以元组为键的字典,如下所示:

{('Friday', 0): 108, ('Friday', 1): 110, ('Friday', 2): 75, ... ('Sunday', 23): 120}

我试图建立一个条形图,用X轴的字典键和Y轴的字典值:
trace0 = go.Bar(
    x=pump_dry_day_beh_dic.keys(),
    y=pump_dry_day_beh_dic.values(),
    name ='yyy'

)

fig = tools.make_subplots(rows=1, cols=1, specs=[[{}]],
                          shared_xaxes=True, shared_yaxes=True,
                          vertical_spacing=0.001)

fig.append_trace(trace0, 1, 1)
fig.append_trace(trace1, 1, 1)

fig['layout'].update(height=600, width=1000,  title='xxx')
fig['layout']['xaxis1'].update(title='day-hour')
fig['layout']['yaxis1'].update(title='Values')
plotly.offline.iplot(fig, filename=' xxx')

但我发现了以下错误:
 The 'x' property is an array that may be specified as a tuple,
    list, numpy array, or pandas Series

另一方面,如果我把上面的代码改成下面的代码,结果会得到一个空的图。
   x=list(pump_dry_day_beh_dic.keys()),
    y=list(pump_dry_day_beh_dic.values()),
    name ='yyyy'

我有办法解决这个问题吗?
谢谢您,

最佳答案

既然你在这里有标签…

import pandas as pd

pump_dry_day_beh_dic = {('Friday', 0): 108, ('Friday', 1): 110,
                        ('Friday', 2): 75, ('Sunday', 23): 120}
pd.DataFrame([pump_dry_day_beh_dic]).T.plot.bar()

python - 带元组键的字典中的条形图-LMLPHP

10-06 15:50