有没有办法在剧情中制作日志2d直方图?我不确定这是否可能。
这是有效的matplotlib代码:
%matplotlib inline
import math
from matplotlib.colors import LogNorm
print len(list_length_view)
%time xy = [(math.log10(x[0]), math.log10(x[1])) for x in list_length_view if x[0] > 0 and x[1] > 0]
print len(xy)
## Why are there negative lengths or view counts!?!?
plt.hist2d([x[0] for x in list_length_view], [x[1] for x in list_length_view],
bins=(40, 60), range=numpy.array([(0, 10000), (0, 1000000)]),
norm=LogNorm(), cmap='Oranges')
cb1 = plt.colorbar()
plt.gca().set_xlabel(r'Clip Duration in Seconds')
plt.gca().set_ylabel(r'Views Per Clip')
cb1.set_label(r'Total Clips')
然而,我最初的目标是在情节上做到这一点。这是我到目前为止尝试使用的代码:
data4 = Data([
Histogram2d(
x=[x[0] for x in list_length_view], #Durations of highlights
y=[y[1] for y in list_length_view], # Views fo hgihlights
nbinsx=10,
nbinsy=10,
)])
layout4 = dict(
title='Public Highlight Analysis',
yaxis=YAxis(
title = 'Average Number of Views'),
xaxis1=XAxis(
title = "Duration of Highlight in Seconds")
)
fig3 = Figure(data=data4, layout=layout4)
py.iplot(fig3)
我也尝试过将matplotlib转换成情节。
def plot_mpl_fig():
xy = [(math.log10(x[0]), math.log10(x[1])) for x in list_length_view if x[0] > 0 and x[1] > 0]
plt.hist2d([x[0] for x in xy], [x[1] for x in xy],
bins=200, range=numpy.array([(-1, 4), (-1, 6)]),
norm=LogNorm(), cmap='Oranges')
cb1 = plt.colorbar()
plt.gca().set_xlabel(r'Log$_{10}$(Clip Duration in Seconds)')
plt.gca().set_ylabel(r'Log$_{10}$(Views Per Clip)')
cb1.set_label(r'Total Clips')
plot_mpl_fig()
mpl_fig1 = plt.gcf()
py_fig1 = tls.mpl_to_plotly(mpl_fig1, verbose=True)