如何绘制具有散景和正确方向角的椭圆?

How to plot an ellipse with bokeh and a correct orientation angle?

我想绘制一个基于两个焦点 f1 和 f2 以及第三个点的椭圆。但是由于某种原因,我计算的给定角度的椭圆方向显示不正确。

我是不是漏掉了一些基本的东西?为什么散景不以 pi/4 的给定角度定向椭圆?

这是我的示例代码:

import numpy as np
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
from bokeh.models import Range1d
output_notebook()

f1 = np.array([0,0])
f2 = np.array([3,3])
point = np.array([1,3])

tools = "hover, box_zoom, undo, crosshair"
p = figure(tools=tools)
p.circle(f1[0], f1[1], radius = 0.05, alpha=0.5)
p.circle(f2[0], f2[1], radius = 0.05, alpha=0.5)
p.circle(point[0], point[1], radius = 0.05, color='red')

center = (f2 - f1)/2 + f1
print(center)

angle = np.arctan2((f2 - f1)[1], (f2 - f1)[0])
print(np.rad2deg(angle))
# minor axis
a = (np.linalg.norm(f2-point) + np.linalg.norm(f1-point))/2
# major axis
c = np.linalg.norm((f2 - f1)/2)
# b = np.sqrt(a**2 - c**2)/2
b = 0.2

p.circle(center[0], center[1], radius = 0.05, color='orange')
p.ellipse(x=center[0], y=center[1], width=2*a, height=2*b, angle=angle, fill_color="yellow", fill_alpha = 0.4)
p.x_range = Range1d(-2, 4)
p.y_range = Range1d(-2, 4)
show(p)

这是一个尚未解决的相当困难的问题:https://github.com/bokeh/bokeh/issues/7965

tl;dr:角度基本上使用与数据范围比不对应的屏幕像素比。在您的特定情况下,"squish" 主要绘图区域是工具栏和轴。如果删除它们,则该区域将是完美的正方形并且角度将是正确的。

我有一个类似的问题,通过改变轴范围解决了它。它没有任何意义,但对于这个例子,椭圆在扩展 y_range 时是对齐的:

from
p.y_range = Range1d(-2, 4)

to
p.y_range = Range1d(-2, 4.35)