1

在此处输入图像描述

这是迄今为止我使用 Plotly 和 iPython 创建的条形图。显然这很难阅读。我想要做的是在 x 轴上创建箱。例如,为 0-50 的 x 值创建 1 个总 y 值。和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)
4

2 回答 2

7

您可以使用 PlotlyHistogram并选择您的垃圾箱的大小,如下例所示:

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/

于 2015-07-20T18:23:39.080 回答
1

您可以在此处查看更多示例。

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')

你将会有,

在此处输入图像描述

于 2015-07-20T05:46:42.330 回答