我正在寻找一种使用Plotly,X轴上带有日期的数据以及Y轴上一个表中的值的方式图。然后,我希望能够像Plotly Histogram binning示例https://plot.ly/python/aggregations/#histogram-binning
中那样按周,日,月等动态(即,使用小部件)对数据进行分组。具有相同或相似的功能是可以接受的,只要我可以让图表动态地执行此操作,即无需创建全新的图
我尝试使用文档中概述的直方图合并,但是由于直方图依赖于从表中计数行而不是直接从表中读取值并将其用作直方图高度,因此无法正常工作。
该功能似乎不适用于条形图
我的数据按这样排列在python pandas数据框中
Date Count
0 2018-01-23 28418
1 2018-08-01 25403
现在的代码本身是:
data = [dict(
x = final['Date'],
y = final['Cage Poll [cases]'],
autobinx = False,
autobiny = True,
marker = dict(color = 'rgb(220, 20, 127)'),
name = 'test',
type = 'histogram',
normed = 'True',
xbins = dict(
#end = '2016-12-31 12:00',
size = 'M1',
#start = '1983-12-31 12:00'
)
)]
layout = dict(
paper_bgcolor = 'rgb(240, 240, 240)',
plot_bgcolor = 'rgb(240, 240, 240)',
title = '<b>Data sampled from daily reports</b>',
showlegend = True,
xaxis = dict(
title = 'Date',
type = 'date'
),
yaxis = dict(
title = 'Count',
type = 'linear'
),
updatemenus = [dict(
x = 0.1,
y = 1.15,
xref = 'paper',
yref = 'paper',
yanchor = 'top',
active = 1,
showactive = True,
buttons = [
dict(
args = ['xbins.size', 'D1'],
label = 'Day',
method = 'restyle',
), dict(
args = ['xbins.size', 'D7'],
label = 'Week',
method = 'restyle',
), dict(
args = ['xbins.size', 'M1'],
label = 'Month',
method = 'restyle',
), dict(
args = ['xbins.size', 'M3'],
label = 'Quarter',
method = 'restyle',
), dict(
args = ['xbins.size', 'M6'],
label = 'Half Year',
method = 'restyle',
), dict(
args = ['xbins.size', 'M12'],
label = 'Year',
method = 'restyle',
)]
)]
)
fig_dict = dict(data=data, layout=layout)
iplot(fig_dict, validate=False)
答案 0 :(得分:0)
是的,您可以将histfunc
跟踪的Histogram
参数设置为"sum"
(默认为"count"
)。有关histfunc
的更多信息,请参见:https://plot.ly/python/histograms/