3

我正在尝试在服务器上绘制不同大小的矩形。我已经想出了如何使用 hold() 一次绘制它们,这就是我得到的

http://postimg.org/image/mh8z0z6nz/

这是我用来绘图的代码

import bokeh.plotting as bk
from bokeh.plotting import *

html_title="height=%r and width='%r'"%(height,width)
bk.output_file("maxrects.html",title="MAXRECTS")                #saving output to a file
bk.figure(plot_width=600,plot_height=600,title=html_title)      #plot specifics


bk.hold()                                                       
x_cor=[]
y_cor=[]
b_width=[]
b_height=[]


bk.rect([width/2],                                              #plotting the bin
    [int(height)/2],
    [width],
    [int(height)],fill_color="crimson")


bk.hold()                                                       #disables overwriting of         any previous glyph


for pr in maxbin.usedRectangles:                                
    b_x=pr.x+pr.width/2                                         #gets centre co-ordinates       of each used rectangle
    b_y=pr.y+pr.height/2
    x_cor.append(int(b_x))
    y_cor.append(int(b_y))
    b_width.append(int(pr.width))
    b_height.append(int(pr.height))

bk.rect(x_cor,                                                  #plotting function
    y_cor,
    b_width,
    b_height,fill_color="black")
 bk.save()                                                      #saves the output
 bk.show()              

高度和宽度由用户输入,bin(crimson) 被初始化。UsedRectangles 包含所有黑色矩形(x,y,width,height 是每个矩形对象的属性)

我想一个接一个地将每个对象发送到一个会话。基本上绘图应该是实时的(动态的)。矩形应该一个接一个地绘制。任何帮助将不胜感激!

matplotlib 的解决方法也是可以接受的

4

0 回答 0