Python 散景:矩形未使用其他字形渲染

Python Bokeh: Rect not rendering with another glyph

下面我有一些关于绘图上的圆形和矩形的代码。

from bokeh.plotting import figure, show
from bokeh.models import LinearAxis, Range1d
from bokeh.resources import settings
from bokeh.models import Legend
from bokeh.io import export_svg



def ExScore(Xax,Yax):

  #X and Y axes
  xfactors = ['-100', '0', '100', '200', '300', '400' ]
  yfactors = ['-100', '-85', '-50', '50', '200', '400']

  #Coordinates for the heatmap rectangles. It should be a grid of 3 across and 5 high
  xr = ['-16.67','-16.67','-16.67','-16.67','-16.67','249.99','249.99','249.99','249.99','249.99','416.65','416.65','416.65','416.65','416.65']
  yr = ['-92.5','-67.5','0','125','300','-92.5','-67.5','0','125','300','-92.5','-67.5','0','125','300']

  #Colors for the rectangles
  colors = [
  '#2ECC71','#82E0AA','#D5F5E3',
  '#2ECC71','#82E0AA','#D5F5E3',
  '#2ECC71','#82E0AA','#D5F5E3',
  '#2ECC71','#82E0AA','#D5F5E3',
  '#2ECC71','#82E0AA','#D5F5E3',
  ]

  #Creating figure
  p = figure(title="ExampleHeatMap", tools="hover", toolbar_location=None,
       x_range=xfactors, y_range=yfactors, plot_width = 500, plot_height = 500)

  #Making axes invisible
  p.xgrid.visible = False
  p.ygrid.visible = False

  #Rendering rectangles that won't show
  p.rect(xr,yr, fill_color=colors, line_color='white', width=100, height=100, fill_alpha=1.0)

  #Rendering circle that does show
  f1 = p.circle(Xax, Yax, size=10, color='#000000', fill_alpha=1.0)

  #Adding legend
  legend = Legend(items=[
      ("Example" , [f1])
  ])
  p.add_layout(legend, 'right')

  show(p)


x = []
y = []

x.append('100')

y.append('50')

ExScore(x,y)

我已经解决了这里的一些其他问题(更正坐标数和精度,调整 width/height/color,尝试使用 output_notebook,确保绘图点和数据统一 [即字符串], ETC。 )。无论我做了什么改变,我都无法让热图呈现在圆圈下方(或根本无法呈现),呈现如下图:

我已经按照我所知道的方式进行了测试,但无论出于何种原因,矩形都不会呈现。这可能是我遗漏的一些简单的东西,但在 SO 中尝试其他解决方案还没有帮助。我正在使用散景版本 2.4.2。如果有人可以提供方向,我将不胜感激。

请检查这是否是您想要的:

def ExScore(Xax,Yax):
    xfactors = [-100.0, 0.0, 100.0, 200.0, 300.0, 400.0]
    yfactors = [-100.0, -85.0, -50.0, 50.0, 200.0, 400.0]

    #Coordinates for the heatmap rectangles. It should be a grid of 3 across and 5 high
    xr = [-16.67, -16.67, -16.67, -16.67, -16.67, 249.99, 249.99, 249.99, 249.99, 249.99, 416.65, 416.65, 416.65, 416.65, 416.65]
    yr = [-92.5, -67.5, 0.0, 125.0, 300.0, -92.5, -67.5, 0.0, 125.0, 300.0, -92.5, -67.5, 0.0, 125.0, 300.0]

    #Colors for the rectangles
    colors = [
    '#2ECC71','#82E0AA','#D5F5E3',
    '#2ECC71','#82E0AA','#D5F5E3',
    '#2ECC71','#82E0AA','#D5F5E3',
    '#2ECC71','#82E0AA','#D5F5E3',
    '#2ECC71','#82E0AA','#D5F5E3',
    ]

    #Creating figure
    p = figure(title="ExampleHeatMap", tools="hover", toolbar_location=None,
       plot_width = 500, plot_height = 500)

    #Making axes invisible
    p.xgrid.visible = False
    p.ygrid.visible = False

    #Rendering rectangles that won't show
    p.rect(xr,yr, fill_color=colors, line_color='white', width=100, height=100, fill_alpha=1.0)

    #Rendering circle that does show
    f1 = p.circle(Xax, Yax, size=10, color='#000000', fill_alpha=1.0)

    #Adding legend
    legend = Legend(items=[
      ("Example" , [f1])
    ])
    p.add_layout(legend, 'right')

    show(p)

生成的图形如下所示: