My Coding > Programming language > Python > Python graphics > Matplotlib > Matplotlib Widgets > How to remove red line in Matplotlib Slider

How to remove red line in Matplotlib Slider

Usually, by default, Matplotlib Slider have tin red line at the initial value, which is convenient in many cases. But sometimes it is confusing, specially when you redefine sliders during work. And the question is – how to remove this thin red line.

First of all, you can have a look at this video to see how this red line looks like.

The standard way of coding Slider is:


ax_x = plt.axes([0.20, 0.25, 0.55, 0.05])
s_x = Slider(ax_x, 'name', min_val, max_val, valinit=initial_val)

def slider_update(val):
    some_variable = s_x.val

s_x.on_changed(slider_update)

In order to remove red line, it is easy to plot it with 0 thickness:


s_x = Slider(ax_x, 'name', min_val, max_val, valinit=initial_val)
s_x.vline._linewidth = 0

for horizontal Sliders (where the line is vertical), and


s_y = Slider(ax_y, 'name', min_val, max_val, valinit=initial_val, orientation="vertical")
s_y.hline._linewidth = 0

For vertical Sliders, where this thin red line is horizontal.


Published: 2022-09-24 21:45:20
Updated: 2022-09-24 21:45:56

Last 10 artitles


9 popular artitles

© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.