Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中,是否有一个类似于直方图分块的条形图?_Python_Python 3.x_Pandas_Plotly - Fatal编程技术网

在Python中,是否有一个类似于直方图分块的条形图?

在Python中,是否有一个类似于直方图分块的条形图?,python,python-3.x,pandas,plotly,Python,Python 3.x,Pandas,Plotly,我正在寻找一个路线图,使用Plotly,X轴上有日期的数据,Y轴上有表格中的值。然后,我希望能够按周、日、月等动态地(即使用小部件)对数据进行分组,如Plotly Histogram binning示例中所示 具有相同或类似的功能是可以接受的,只要我可以让图表动态地这样做,即不需要创建一个全新的绘图 我尝试过使用文档中概述的直方图分块,但是这不起作用,因为直方图依赖于从表中计算行数,而不是直接从表中读取值并将其用作直方图高度 然而,相同的功能似乎不适用于条形图 我的数据是这样排列在python数

我正在寻找一个路线图,使用Plotly,X轴上有日期的数据,Y轴上有表格中的值。然后,我希望能够按周、日、月等动态地(即使用小部件)对数据进行分组,如Plotly Histogram binning示例中所示

具有相同或类似的功能是可以接受的,只要我可以让图表动态地这样做,即不需要创建一个全新的绘图

我尝试过使用文档中概述的直方图分块,但是这不起作用,因为直方图依赖于从表中计算行数,而不是直接从表中读取值并将其用作直方图高度

然而,相同的功能似乎不适用于条形图

我的数据是这样排列在python数据框中的

    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)
data=[dict(
x=最终[“日期”],
y=最终['Cage民意测验[案例]”,
autobinx=False,
autobiny=True,
标记=dict(颜色='rgb(220,20,127)',
名称='测试',
类型='直方图',
normed=‘真’,
xbins=dict(
#结束='2016-12-31 12:00',
大小='M1',
#开始时间='1983-12-31 12:00'
)
)]
布局=记录(
纸张颜色='rgb(240240240)',
plot_bgcolor='rgb(240240240)',
标题=‘从日报中采样的数据’,
showlegend=True,
xaxis=dict(
标题='日期',
类型='日期'
),
yaxis=dict(
标题='计数',
类型='线性'
),
updatemenus=[dict(
x=0.1,
y=1.15,
外部参照='纸张',
yref='纸张',
yanchor='顶部',
活动=1,
showactive=True,
按钮=[
口述(
args=['xbins.size','D1'],
标签='天',
方法='restyle',
),迪克特(
args=['xbins.size','D7'],
标签='周',
方法='restyle',
),迪克特(
args=['xbins.size','M1'],
标签='月份',
方法='restyle',
),迪克特(
args=['xbins.size','M3'],
标签='四分之一',
方法='restyle',
),迪克特(
args=['xbins.size','M6'],
标签=‘半年’,
方法='restyle',
),迪克特(
args=['xbins.size','M12'],
标签='年',
方法='restyle',
)]
)]
)
图dict=dict(数据=数据,布局=布局)
iplot(图2,验证=False)

是的,您可以将
直方图的
histfunc
参数设置为
“sum”
(默认值为
“count”
)。有关
histfunc
的更多信息,请访问: