获取在图形上绘制的所有对象(艺术家) [英] Get all objects (artists) drawn on a figure

查看:58
本文介绍了获取在图形上绘制的所有对象(艺术家)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望建立一种可以将正常图形(暗线,白色/透明背景)转换为伪反转图形(浅线,黑色/透明背景)的方法.我可以对图像进行倒置处理,但是直接倒置的颜色看起来很糟糕,因此我想(尝试)创建一组颜色到另一组颜色的映射,然后将其应用于所有添加的艺术家(在所有轴上).

I'm hoping to setup a method which can convert a normal figure (dark lines, white/transparent background) to a pseudo-inverted figure (light lines, black/transparent background). I could just post-process invert the image, but directly inverted colors look awful, so I'd like to instead (try to) create a mapping from one set of colors to another, and then apply this to all artists which have been added to (all axes on) a figure.

有没有办法访问已添加到图形中的所有对象(例如文本、散点图、线条、刻度标签等)?

我的动机是自动创建图形的白色背景和黑色背景版本.出版物(例如)总是(我认为)需要白色背景图,而演示文稿(即谈话幻灯片)可能需要黑色背景图.虽然设置一个标志并根据它更改每种颜色不会很麻烦,例如

my motivation is to automatically create white-background and black-background versions of figures. White-background figures will always (I think) be required for publications (for example), while black-background figures may be better for presentations (i.e. talk slides). While it wouldn't be that much trouble to setup a flag, and change each color based on that, e.g.

if dark:
    col_line = 'cyan'
    col_bg = 'black'
else:
    col_line = 'red'
    col_bg = 'white'

# ... plot ...

执行类似的操作会更酷,更方便(尽管有开销)

It would be much cooler and more convenient (despite overhead) to do something like,

fig.savefig('dark.pdf')
invert(fig)
fig.savefig('light.pdf')

推荐答案

递归调用 .get_children(),在返回的列表为空时停止.

Recursively call .get_children(), stop when the returned list is empty.

这篇关于获取在图形上绘制的所有对象(艺术家)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆