IIUC you can set the x and y limits based on the line you want to bound by:
# Data for first and second lines
x1 = [3, 4]
y1 = [5, 8]
x2 = [2, 5]
y2 = [4, 9]
# Create the plot
fig, ax = plt.subplots()
# Plot the first set of data
ax.plot(x1, y1, label="Line 1")
# Set the x and y limits based on the first line with 5% padding
padding_x = 0.05 * (max(x1) - min(x1))
padding_y = 0.05 * (max(y1) - min(y1))
ax.set_xlim(min(x1) - padding_x, max(x1) + padding_x)
ax.set_ylim(min(y1) - padding_y, max(y1) + padding_y)
# Plot the second set of data
ax.plot(x2, y2, label="Line 2", color='red')
# Show the plot
plt.show()