I am trying to create a plot with vertical bars equal to score length, AND with a radiobutton which enables the user to choose which level scores he/she wants to see, as such: Button 1: Shows the pointscores of John and Daniel in level 1. Button 2: Shows the pointscores of John and Daniel in level 2. Button 3: Shows the pointscores of John and Daniel in level 3. ... And so on. If you run the code the idea of the design should be clear.
My general problem is how to connect the radiobutton to the values of the items, in this example called "level1", "level2" and "level3" (lines 19, 20 & 21). All I have as a scabelon is a color-changer (disabled), from Matplotlib.
I have tried a lot of googeling, but are only able to come up with answers of how to DESIGN the radiobutton itself, instead of HOW TO CONNECT it to my input.
I hope that the question is clear. Thank you
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
john_level1 = 10
john_level2 = 2
john_level3 = 18
daniel_level1 = 11
daniel_level2 = 0
daniel_level3 = 6
fig, ax = plt.subplots()
plt.subplots_adjust(left=0.35, bottom=0.25)
people = ("John", "Daniel")
y_pos = np.arange(len(people))
level1 = john_level1, daniel_level1
level2 = john_level2, daniel_level2
level3 = john_level3, daniel_level3
plt.axis([0, 12, -1, 2])
axcolor = 'lightgoldenrodyellow'
plt.barh(y_pos, level1, align='center', alpha=0.5)
plt.yticks(y_pos, people)
plt.title('Individuel Points', fontsize=14, fontweight='bold')
#################
# RADIO BUTTONS # Originally a color-changer from Matplotlib
#################
rax = plt.axes([0.015, 0.45, 0.25, 0.25], axisbg=axcolor)
radio = RadioButtons(rax, ('Score at Level 1', 'Score at Level 2', 'Score at Level 3'), active=0)
def raidfunc(label):
# l.set_color(label)
fig.canvas.draw_idle()
radio.on_clicked(raidfunc)
plt.show()