Reputation: 173
is there a way to create a zoom-in-rectangle that draws across subplots or outside the axis? The current matplotlib navigation zoom-in-rectangle allows you to click and drag the rectangle within one axis at a time, but I want the option to extend the dash rectangle wherever the mouse is.
Upvotes: 0
Views: 1676
Reputation: 339240
The idea can be to create a new axes which fills the entire figure and make it transparent. You can then use a rectange selector for that axes.
from matplotlib.widgets import RectangleSelector
import numpy as np
import matplotlib.pyplot as plt
fig, axes = plt.subplots(2,2)
for ax in axes.flat:
ax.scatter(np.random.rand(7), np.random.rand(7), c=np.random.rand(7))
def select(eclick, erelease):
x1, y1 = eclick.xdata, eclick.ydata
x2, y2 = erelease.xdata, erelease.ydata
pass
overax = fig.add_axes([0,0,1,1])
overax.patch.set_alpha(0)
overax.axis("off")
rs = RectangleSelector(overax, select,
drawtype='box', useblit=True,
button=[1, 3],
minspanx=5, minspany=5,
spancoords='pixels',
interactive=True)
plt.show()
Upvotes: 1