这可能听起来并不容易。更改限制时,您将更改限制,以使回调无限期运行,从而使窗口崩溃。
因此,我将选择另一个解决方案,使用第二个轴。假设您有两个轴:
放大后,
ax2回调函数可以更改
ax您喜欢的限制。这就是屏幕上显示的内容。
import matplotlib.pyplot as plt# Some toy datax_seq = [x / 100.0 for x in xrange(1, 100)]y_seq = [x**2 for x in x_seq]# ax is emptyfig, ax = plt.subplots()ax.set_navigate(False)# ax2 will hold the plot, but has invisible labelsax2 = fig.add_subplot(111,zorder=2)ax2.scatter(x_seq, y_seq)ax2.axis("off")ax.set_xlim(ax2.get_xlim())ax.set_ylim(ax2.get_ylim())## Declare and register callbacksdef on_lims_change(axes): # change limits of ax, when ax2 limits are changed. a=ax2.get_xlim() ax.set_xlim(0, a[1]-a[0]) a=ax2.get_ylim() ax.set_ylim(0, a[1]-a[0])ax2.callbacks.connect('xlim_changed', on_lims_change)ax2.callbacks.connect('ylim_changed', on_lims_change)# Showplt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)