【问题标题】:Printing multiple plots in the web browser using mpld3使用 mpld3 在 Web 浏览器中打印多个图
【发布时间】:2018-08-16 05:14:52
【问题描述】:

在代码中,我试图在 Web 浏览器中打印 3 个图,但只有 2 个图(high2 和 high3)正在打印。你能告诉我如何获得所有 3 个地块吗?谢谢

#Plot 1
for index, row in Taskee_assi.iterrows():
   new_list1.append(row.AddDateTimeInUTC_x.hour)  
plt.title("Overall Tasks assigned WRT Time")        
plt.hist(new_list1, bins=50) 
high1 = plt.figure()
list_sum_1 = sum(new_list1)
list_num_1 = len(new_list1)
list_avg1 = list_sum_1/list_num_1
print('Average of Overall Tasks Assigned wrt Time',list_avg1)

#Plot 2
for index,row in dummy_var2.iterrows():
   new_list2.append(row.EventDateTimeInUTC.hour)
plt.title("Time at which Task is read ")        
plt.hist(new_list2, bins=50) 
high2 = plt.figure()
list_sum_2 = sum(new_list2)
list_num_2 = len(new_list2)
list_avg2 = list_sum_2/list_num_2
print('Average Time in which Tasks are read',list_avg2)

#Plot 3
for index,row in dummy_var4.iterrows():
   new_list3.append(row.EventDateTimeInUTC.hour)
plt.title("Time at which Comments are read ")        
plt.hist(new_list3, bins=50)  
high3 = plt.figure()
list_sum_3 = sum(new_list3)
list_num_3 = len(new_list3)
list_avg3 = list_sum_3/list_num_3
print('Average Time in which Comments are read (in terms of time)',list_avg3)

html1 = mpld3.fig_to_html(high1)
html2 = mpld3.fig_to_html(high2)
html3 = mpld3.fig_to_html(high3)
serve(html1+html2+html3)

【问题讨论】:

标签: python-3.x matplotlib mpld3


【解决方案1】:

我找到了另一个答案。我为该图创建了子图,然后在浏览器中显示相同的子图。使用这种方法可以在网络浏览器中显示任意数量的图。

for index, row in Taskee_assi.iterrows():
        new_list1.append(row.AddDateTimeInUTC_x.hour)
    #For Subplot 1.1
    list_sum_1 = sum(new_list1)
    list_num_1 = len(new_list1)
    list_avg1 = list_sum_1/list_num_1
    print('Average of Overall Tasks Assigned wrt Time',list_avg1)
    for index,row in dummy_var2.iterrows():
        new_list2.append(row.EventDateTimeInUTC.hour)
    #For Subplot 1.2
    list_sum_2 = sum(new_list2)
    list_num_2 = len(new_list2)
    list_avg2 = list_sum_2/list_num_2
    print('Average Time in which Tasks are read',list_avg2)
    for index,row in dummy_var4.iterrows():
        new_list3.append(row.EventDateTimeInUTC.hour)
    #For Subplot 1.3
    list_sum_3 = sum(new_list3)
    list_num_3 = len(new_list3)
    list_avg3 = list_sum_3/list_num_3
    print('Average Time in which Comments are read ',list_avg3)


    f, (ax1, ax2, ax3) = plt.subplots(3,figsize=(10,10))
    ax1.hist(new_list1, bins=50)
    ax1.set_title("Overall Tasks assigned WRT Time")
    ax2.hist(new_list2, bins=50)
    ax2.set_title("Time at which Task is read ")
    ax3.hist(new_list3, bins=50) 
    ax3.set_title("Time at which Comments are read ")


    f.subplots_adjust(top=0.90, bottom=0.08, left=0.10, right=0.95, hspace=0.55,wspace=0.35)
    plt.setp([a.get_xticklabels() for a in f.axes[:0]], visible=False)

    html1 = mpld3.fig_to_html(f)    

【讨论】:

    猜你喜欢
    • 2018-05-02
    • 2023-03-12
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多