SpanSelector: How to set selection with code?

Here is the SpanSelector demo with a button added to select a default range. How do I make the button change the highlighted region of the plot?

import matplotlib.pyplot as plt
import numpy as np

from matplotlib.widgets import SpanSelector, Button

# Fixing random state for reproducibility

fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6))

x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2 * np.pi * x) + 0.5 * np.random.randn(len(x))

ax1.plot(x, y)
ax1.set_ylim(-2, 2)
ax1.set_title('Press left mouse button and drag '
              'to select a region in the top graph')

line2, = ax2.plot([], [])

def onselect(xmin, xmax):
    indmin, indmax = np.searchsorted(x, (xmin, xmax))
    indmax = min(len(x) - 1, indmax)

    region_x = x[indmin:indmax]
    region_y = y[indmin:indmax]

    if len(region_x) >= 2:
        line2.set_data(region_x, region_y)
        ax2.set_xlim(region_x[0], region_x[-1])
        ax2.set_ylim(region_y.min(), region_y.max())

span = SpanSelector(
    props=dict(alpha=0.5, facecolor="tab:blue"),
# Set useblit=True on most backends for enhanced performance.

ax_preset = fig.add_axes([0.81, 0.05, 0.1, 0.075])
button_preset = Button(ax_preset, 'Preset')

def onpreset(event):
    # ??? 
    # span.set_active_selection(1, 3)
    # Can directly call onselect, but that won't update the selection


What change are you trying to induce?

I wish to change the the highlighted region drawn on ax1 by the span widget by means other than dragging on the plot. For example: setting a fixed range at the press of a button.
How can I modify onpreset in the above example to make that happen?

Oh. you can assign directly to extents. Is that supported? Should that be better documented?

This does what I was looking for:

def onpreset(event):
    span.extents = (1,3)

property extents
Return extents of the span selector.

That description doesn’t help. Nothing says that extents are the current selection. If I even saw it, I might have just assumed is something concerning presentation only. I found it jumping into the source code with expectation of monkey patching something together.

A better description might be “Returns the axis values of the start and end points of the current selection. If there is no selection then the start and end values will be the same.” ?