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

Bar charts with xaxis bins using Plotly or Matplotlib?

这是迄今为止我使用 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)

您可以查看更多示例here

import numpy as np
import pylab as P

mu, sigma = 200, 25
x = mu + sigma*P.randn(10000)

P.hist(x, 50)
P.show()

以上产生:

如果你这样做,

P.figure()
P.hist(x, range(100,300,10))
P.savefig('b.png')

你将拥有,

您可以使用 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)
    )
])

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