- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
运行下面的代码片段后,
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
plotted_ellipse = Ellipse((0, 0), 10, 10)
unplotted_ellipse = Ellipse((0, 0), 10, 10)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.add_patch(plotted_ellipse)
ax.set_aspect('equal')
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
我在使用 contains_point
时得到以下结果方法
In [6]: plotted_ellipse.contains_point((0, 0))
Out[6]: False
In [7]: unplotted_ellipse.contains_point((0, 0))
Out[7]: True
这对我来说毫无意义。这可能是一个错误吗?或者是否有测试补丁对象是否包含点的首选方法?
使用 matplotlib
版本 1.5.1
最佳答案
这是因为您正在检查数据坐标中绘制的椭圆中的点,而当您向 ax 添加路径时,其坐标会转换为显示坐标。根据docs :
The convention of checking against the transformed patch stems from the fact that this method is predominantly used to check if display coordinates (e.g. from mouse events) are within the patch. If you want to do the above check with data coordinates, you have to properly transform them first
因此,如果您想检查数据坐标中的一个点,您必须先将其转换为显示坐标:
point = plotted_ellipse.get_transform().transform((0,0))
print(plotted_ellipse.contains_point(point))
>>> True
有关坐标系的说明,请参阅 here .
关于python - 为什么绘制 matplotlib 补丁会损坏 contains_point?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39583674/
对于 matplotlib.patches,patch.contains_point(xy) 方法似乎与 patch.get_path().contains_point(xy) 不同,至少在拥有之后将
我正在尝试根据 matplotlib Path 对象选择数据区域,但是当路径包含贝塞尔曲线(不仅仅是直线)时,所选区域不会完全填充曲线。看起来它正在尝试,但曲线的远侧被切断了。 例如,以下代码定义了一
我使用 matplotlib 1.15.1 并尝试生成这样的散点图: 椭圆的大小是固定的,用中心坐标、宽度、高度和角度(从外部提供)绘制:我不知道它们的方程式是什么。 g_ell_center = (
运行下面的代码片段后, import matplotlib.pyplot as plt from matplotlib.patches import Ellipse plotted_ellipse =
我们有一个 HitTest 用例,它还希望考虑路径实际边界上的点。我们正在使用 matplotlib.path.contains_points 来测试一堆点,它对我们来说效果很好。今天我发现它对边界上
我正在使用 matplotlib.patches.Polygon 来更新图形上的一些彩色补丁,并且我在代码的每次迭代中都这样做。因为我已经用这种方式在我的代码中定义了补丁,所以我想使用 函数 cont
我正在尝试使用 Matplotlib 查找多边形路径中包含的所有点,但它似乎遗漏了一些点。更具体地说,我的路径是一个矩形,并且点位于底层统一网格上。在下面的测试脚本中,它不会将位于多边形顶线上的点视为
我一直在寻找 MATLAB 的 inpolygon() 的 python 替代品,我发现 contains_points 是一个不错的选择。 但是,文档有点空洞,没有说明 contains_point
问题: 函数中的半径参数contains_point in matplotlib.path定义不一致。此函数检查指定点是在封闭路径的内部还是外部。 radius 参数用于使路径稍微变小/变大(取决于半
我是一名优秀的程序员,十分优秀!