【发布时间】:2015-06-03 16:55:36
【问题描述】:
我有一个非常大的数据集,并且希望用户能够沿着轴滑动来查看数据的各个部分。我正在尝试利用滑块示例,但我不确定如何更新图表。希望有人可以用这个解释一些幕后花絮。
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.widgets import Slider, Button, RadioButtons
fig = plt.figure()
ax = fig.add_subplot(111)
fig.subplots_adjust(left=0.25, bottom=0.25)
min0 = 0
max0 = 10
x = np.arange(10)
y = np.arange(10)
im1 = plt.scatter(x,y, s=3, c=u'b', edgecolor='None',alpha=.75)
#most examples here return something iterable
plt.ylim([0,10])#initial limits
axcolor = 'lightgoldenrodyellow'
axmin = fig.add_axes([0.25, 0.1, 0.65, 0.03], axisbg=axcolor)
axmax = fig.add_axes([0.25, 0.15, 0.65, 0.03], axisbg=axcolor)
smin = Slider(axmin, 'Min', 0, 10, valinit=min0)
smax = Slider(axmax, 'Max', 0, 10, valinit=max0)
def update(val):
plt.ylim([smin.val,smax.val])
ax.canvas.draw()#unsure on this
smin.on_changed(update)
smax.on_changed(update)
plt.show()
【问题讨论】:
标签: python matplotlib widget scatter-plot