我有一个 python 脚本,它提供了一个自定义过滤器,用于使用 matplotlib 进行缩放,以在 GUI 中使用。特别是,我有不同的子图,我只需要更新我正在缩放的子图的视图。如果我使用 plt.draw(),它将更新图形的所有子图。我怎样才能只定位与当前子情节相关的艺术家,换句话说,做类似的事情ax.draw()?
这是一个说明问题的简单示例:
import matplotlib.pyplot as plt
#------------------------------------
# Definition of the initial figure
#------------------------------------
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.plot([0,1],[0,1],'b-')
ax2 = fig.add_subplot(212)
ax2.plot([0,1],[0,1],'r-')
#------------------------------------
# Changing xlim in the 1st subplot with a click
#------------------------------------
def modify_subplot(event):
ax1.set_xlim([0,0.5])
plt.draw() # I want to replace this method with a
# function that updates only the artists
# in ax1 without touching ax2
fig.canvas.mpl_connect('button_press_event', modify_subplot)
#------------------------------------
plt.show()
Run Code Online (Sandbox Code Playgroud)
我试图用 plt.draw() 替换,ax1.draw(fig.canvas.get_renderer())但它没有更新任何东西。
| 归档时间: |
|
| 查看次数: |
240 次 |
| 最近记录: |