Search code examples
pythonmatplotlibwxpythonwxwidgets

How to add a marker on wx slider?


I am developing a python GUI script which required a function to be plotted. I need my plot to vary in real time when I vary certain parameters in the slider. That's not a problem and I successfully implemented those with both wx slider and matplotlib slider.

What I failed to do is to add a "marker" to the slider. Often a particular value of parameter is more interesting than others and we want to "highlight" that value on the slider for our users. What I have in my mind is something like the red vertical line in matplotlib slider which indicates the initial value: enter image description here , but I failed to find any relevant functions to change its location after the slider's creation. We have a drop down list showing different configurations and the value of interest changes with the configurations. I would like my marker to update its location automatically when a new configuration is set.

I would like to ask if it is possible to change that red vertical line in matplotlib slider? If not, are there alternatives in either wxpython or matplotlib that allows me to highlight the value of interest and update its location according to a drop down list?


Solution

  • The slider has a vline attribute which stores the red vertical line. You can change its horizontal position via the set_xdata method.

    slider = Slider(...)
    x = 3.21 # new value to set the line to
    slider.vline.set_xdata([x,x])