Skip to main content
Ctrl+K
Matplotlib 3.10.0.dev759+ge90952ffac 文档 - Home
  • Plot types
  • User guide
  • Tutorials
  • Examples
  • Reference
  • Contribute
  • Releases
  • Gitter
  • Discourse
  • GitHub
  • Twitter
  • Plot types
  • User guide
  • Tutorials
  • Examples
  • Reference
  • Contribute
  • Releases
  • Gitter
  • Discourse
  • GitHub
  • Twitter

Section Navigation

  • 线条、条形和标记
  • 图像、轮廓和场
  • 子图、轴和图形
  • 统计
  • 饼图和极坐标图
  • 文本、标签和注释
  • 颜色
  • 形状和集合
  • 样式表
  • 模块 - pyplot
  • 模块 - axes_grid1
  • 模块 - axisartist
  • 展示
  • 动画
  • 事件处理
  • 杂项
    • 锚定艺术家
    • 识别艺术家是否相交
    • 手动轮廓
    • 坐标报告
    • 自定义投影
    • 自定义 Rc
    • AGG 过滤器
    • Ribbon box
    • 直接向图形添加线条
    • 填充螺旋
    • Findobj 演示
    • 字体索引
    • 字体属性
    • 使用矩形和多边形集合构建直方图
    • 超链接
    • 图像缩略图
    • 使用关键词绘图
    • Matplotlib 标志
    • 多页PDF
    • 多进程
    • 打包气泡图
    • 路径效果演示
    • 将图像打印到标准输出
    • 矢量图形的栅格化
    • 设置和获取属性
    • 将 SVG 滤镜应用于一行
    • SVG 滤镜派
    • 表格演示
    • TickedStroke 路径效果
    • transforms.offset_copy
    • Zorder 演示
  • 3D 绘图
  • 比例尺
  • 专业图表
  • 书脊
  • Ticks
  • 单位
  • 在图形用户界面中嵌入 Matplotlib
  • 小部件
  • 用户演示
  • 示例
  • 杂项
  • 识别艺术家是否相交

备注

前往末尾 下载完整示例代码。

识别艺术家是否相交#

与矩形相交的线条被染成红色,而其他线条则保持蓝色。这个例子展示了 intersects_bbox 函数。

bbox intersect
import matplotlib.pyplot as plt
import numpy as np

from matplotlib.path import Path
from matplotlib.transforms import Bbox

# Fixing random state for reproducibility
np.random.seed(19680801)


left, bottom, width, height = (-1, -1, 2, 2)
rect = plt.Rectangle((left, bottom), width, height,
                     facecolor="black", alpha=0.1)

fig, ax = plt.subplots()
ax.add_patch(rect)

bbox = Bbox.from_bounds(left, bottom, width, height)

for i in range(12):
    vertices = (np.random.random((2, 2)) - 0.5) * 6.0
    path = Path(vertices)
    if path.intersects_bbox(bbox):
        color = 'r'
    else:
        color = 'b'
    ax.plot(vertices[:, 0], vertices[:, 1], color=color)

plt.show()

下载 Jupyter 笔记本: bbox_intersect.ipynb

下载 Python 源代码: bbox_intersect.py

下载压缩包: bbox_intersect.zip

由 Sphinx-Gallery 生成的图库

© Copyright 2002–2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012–2024 The Matplotlib development team.

由 Sphinx 8.0.2创建。

Built from v3.9.2-622-gb01462c9ac-dirty.

Built with the PyData Sphinx Theme 0.15.4.