相关疑难解决方法(0)

绘图中的注释自动放置

我有代码可以轻松地自动处理着色和绘制多个图(对我来说)。我想让注释变得更容易:

目标:如果注释 xy 与前一个注释冲突,请向上移动 - 直到与其他注释不发生冲突。

  1. 如果有一个功能已经能够做到这一点那将是一个梦想,但我找不到。

  2. 否则 - 列出注释并在坐标系中获取其边界框的最佳方法是什么?

我有一个自动着色代码,如下所示:

if chain:
    children = []
    for child in Iplot.axes.get_children():
        if (type(child) is not matplotlib.collections.PathCollection and
            type(child) is not matplotlib.lines.Line2D):
            continue
        children.append(child)
    col_step = 1.0/(len(children)+len(args))
    for child in children:
        child.set_color([Iplot.col,0,1-Iplot.col])
        Iplot.col += col_step
Run Code Online (Sandbox Code Playgroud)

我可以对注释做类似的事情(更改 if 语句和第二个循环的主体),但是 1)我不喜欢这段代码 2)我希望存在更优雅的东西。

python text matplotlib plot-annotations

4
推荐指数
1
解决办法
4177
查看次数

标签 统计

matplotlib ×1

plot-annotations ×1

python ×1

text ×1