Matplotlib 如何格式化滑块

Matplotlib 如何格式化滑块,matplotlib,Matplotlib,我有一个滑块: time_ax = fig.add_axes([0.1, 0.05, 0.8, 0.03]) var_time = Slider(time_ax, 'Time', 0, 100, valinit=10, valfmt='%0.0f') var_time.on_changed(update) 我想自定义此滑块的外观: 我可以将axisbg参数添加到add_axes函数中,这将把默认的白色背景更改为指定的颜色,但这就是我现在所能看到的 那么,如何更改其他滑块组件: 窗台边框(默

我有一个滑块:

time_ax = fig.add_axes([0.1, 0.05, 0.8, 0.03])
var_time = Slider(time_ax, 'Time', 0, 100, valinit=10, valfmt='%0.0f')
var_time.on_changed(update)
我想自定义此滑块的外观:

我可以将
axisbg
参数添加到
add_axes
函数中,这将把默认的白色背景更改为指定的颜色,但这就是我现在所能看到的

那么,如何更改其他滑块组件:

  • 窗台边框(默认值:黑色)
  • 默认值指示器(默认值:红色)
  • 滑块进度(默认值:蓝色)

滑块边框只是
轴的脊椎。可以在构造函数中直接访问进度条进行基本自定义,初始状态指示器是滑块的一个属性。我能够改变所有这些事情:

import matplotlib.pyplot as plt
from matplotlib.widgets import Slider

fig = plt.figure()
time_ax = fig.add_axes([0.1, 0.05, 0.8, 0.03])

# Facecolor and edgecolor control the slider itself
var_time = Slider(time_ax, 'Time', 0, 100, valinit=10, valfmt='%0.0f',
                  facecolor='c', edgecolor='r')

# The vline attribute controls the initial value line
var_time.vline.set_color('blue')

# The spines of the axis control the borders
time_ax.spines['left'].set_color('magenta')
time_ax.spines['right'].set_color('magenta')
time_ax.spines['bottom'].set_color('magenta')
time_ax.spines['top'].set_color('magenta')

定义“ax”框的轴时可以更改的框颜色:

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
t = np.arange(0.0, 1.0, 0.001)
a0 = 5
f0 = 3
s = a0*np.sin(2*np.pi*f0*t)
l, = plt.plot(t,s, lw=2, color='red')
plt.axis([0, 1, -10, 10])

axcolor = 'lightgoldenrodyellow'
axfreq = plt.axes([0.03, 0.25, 0.03, 0.65], axisbg=axcolor)
axamp = plt.axes([0.08, 0.25, 0.03, 0.65], axisbg=axcolor)
sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0)
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0)
# The vline attribute controls the initial value line
samp.vline.set_color('green')