首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >matplotlib check_buttons盒颜色

matplotlib check_buttons盒颜色
EN

Stack Overflow用户
提问于 2015-05-19 14:59:27
回答 1查看 1.1K关注 0票数 3

我使用的是check_buttons小部件,如示例(buttons.html)中所示

在有许多行的绘图中,很难从哪个复选框的文本中知道哪一行是划线的,至少在单击该框并查看用户是否能够分辨出哪一行消失之前是困难的。

有没有人知道复选框的背景色是否可以像图例一样与其affects...something行相同?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-19 15:06:42

您可以将小部件框的颜色设置如下,

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import CheckButtons

t = np.arange(0.0, 2.0, 0.01)
s0 = np.sin(2*np.pi*t)
s1 = np.sin(4*np.pi*t)
s2 = np.sin(6*np.pi*t)

fig, ax = plt.subplots()
l0, = ax.plot(t, s0, visible=False, lw=2)
l1, = ax.plot(t, s1, lw=2)
l2, = ax.plot(t, s2, lw=2)
plt.subplots_adjust(left=0.2)

rax = plt.axes([0.05, 0.4, 0.1, 0.15])
check = CheckButtons(rax, ('2 Hz', '4 Hz', '6 Hz'), (False, True, True))

#Define colours for rectangles and set them
c = ['b', 'g', 'r']    
[rec.set_facecolor(c[i]) for i, rec in enumerate(check.rectangles)]


def func(label):
    if label == '2 Hz': l0.set_visible(not l0.get_visible())
    elif label == '4 Hz': l1.set_visible(not l1.get_visible())
    elif label == '6 Hz': l2.set_visible(not l2.get_visible())
    plt.draw()
check.on_clicked(func)

plt.show()

校验按钮面板将每个勾选框作为matplotlib.patches.Rectangle对象,该对象可以根据需要为定做

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30329239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档