这是迄今为止我使用 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)
)
])
关于python - 使用 Plotly 或 Matplotlib 的带有 xaxis bin 的条形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31509239/