python - 使用 Plotly 或 Matplotlib 的带有 xaxis bin 的条形图?

标签 python matplotlib plotly

enter image description here

这是迄今为止我使用 Plotly 和 iPython 创建的条形图。显然这很难阅读。我想要做的是在 x 轴上创建 bin。例如,为 0-50 的 x 值创建总 y 值的 1 个条。和 50-100。等等。

这可以使用 matplotlib 或 Plotly 来完成吗?

剧情代码:

data = Data([
    Bar(
        x=[tuples[0] for tuples in tuples_list],
        y=[tuples[1] for tuples in tuples_list]
    )
])
layout = dict(
   title='Public Video Analysis',
   yaxis=YAxis(
       title = 'Views'),
   xaxis1=XAxis(
       title = "Duration in Seconds"),
   )
fig = Figure(data=data, layout=layout)
py.iplot(fig)

最佳答案

您可以使用 Plotly 的 Histogram 并选择 bin 的大小,如下例所示:

import plotly.plotly as py
from plotly.graph_objs import *

import numpy as np

x = np.random.randn(500)*100

data = Data([Histogram(x=x,
                       autobinx=False,
                       xbins=XBins(start=min(x),
                                   end=max(x),
                                   size=50)
    )
])

example histogram https://plot.ly/~chelsea_lyn/4551/x/

关于python - 使用 Plotly 或 Matplotlib 的带有 xaxis bin 的条形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31509239/

相关文章:

python - 使用 python pptx 模块在 PowerPoint 中插入一行

python - 如何将多个 EPS 文件放置到 PDF 的单个页面上?

python - 使用 matplotlib 在单独的子图中绘制 Pandas 系列

python - Matplotlib:曲线重叠时如何防止透明颜色叠加?

javascript - 如何在绘图中设置小刻度

python - python unittest doc推荐的惰性导入方法如何做?

python - 在 emacs Python 模式下,如何为文档字符串和代码设置不同的自动填充宽度?

Python - matplotlib 中用于 3D 线图的颜色图

r - 更改将鼠标悬停在绘图中的值上

plot - 如何在 Julia 中制作交互式 plotly