Add radio buttons to :class:`matplotlib.axes.Axes` instance *ax* *labels* A len(buttons) list of labels as strings *active* The index into labels for the button that is active *activecolor* The color of the button when clicked
(self, ax, labels, active=0, activecolor='blue')
| 964 | Connect to the RadioButtons with the :meth:`on_clicked` method |
| 965 | """ |
| 966 | def __init__(self, ax, labels, active=0, activecolor='blue'): |
| 967 | """ |
| 968 | Add radio buttons to :class:`matplotlib.axes.Axes` instance *ax* |
| 969 | |
| 970 | *labels* |
| 971 | A len(buttons) list of labels as strings |
| 972 | |
| 973 | *active* |
| 974 | The index into labels for the button that is active |
| 975 | |
| 976 | *activecolor* |
| 977 | The color of the button when clicked |
| 978 | """ |
| 979 | AxesWidget.__init__(self, ax) |
| 980 | self.activecolor = activecolor |
| 981 | self.value_selected = None |
| 982 | |
| 983 | ax.set_xticks([]) |
| 984 | ax.set_yticks([]) |
| 985 | ax.set_navigate(False) |
| 986 | dy = 1. / (len(labels) + 1) |
| 987 | ys = np.linspace(1 - dy, dy, len(labels)) |
| 988 | cnt = 0 |
| 989 | axcolor = ax.get_facecolor() |
| 990 | |
| 991 | # scale the radius of the circle with the spacing between each one |
| 992 | circle_radius = (dy / 2) - 0.01 |
| 993 | |
| 994 | # defaul to hard-coded value if the radius becomes too large |
| 995 | if(circle_radius > 0.05): |
| 996 | circle_radius = 0.05 |
| 997 | |
| 998 | self.labels = [] |
| 999 | self.circles = [] |
| 1000 | for y, label in zip(ys, labels): |
| 1001 | t = ax.text(0.25, y, label, transform=ax.transAxes, |
| 1002 | horizontalalignment='left', |
| 1003 | verticalalignment='center') |
| 1004 | |
| 1005 | if cnt == active: |
| 1006 | self.value_selected = label |
| 1007 | facecolor = activecolor |
| 1008 | else: |
| 1009 | facecolor = axcolor |
| 1010 | |
| 1011 | p = Circle(xy=(0.15, y), radius=circle_radius, edgecolor='black', |
| 1012 | facecolor=facecolor, transform=ax.transAxes) |
| 1013 | |
| 1014 | self.labels.append(t) |
| 1015 | self.circles.append(p) |
| 1016 | ax.add_patch(p) |
| 1017 | cnt += 1 |
| 1018 | |
| 1019 | self.connect_event('button_press_event', self._clicked) |
| 1020 | |
| 1021 | self.cnt = 0 |
| 1022 | self.observers = {} |
| 1023 |
nothing calls this directly
no test coverage detected