As is often the case on a question like this, you have been too vague for us to comprehensively understand what you do "have". (That is why there are so many conjectures on how to solve your problem. But none of us really know what you have or need to learn.)
That is, is the picture you show a picture of some points taken from some known function? Probably not, since then you would know what the "linear" portion would be. So then you must have some relationhip, sampled at a list of points. You probably have (x,y) pairs only. Are they sampled at some uniform spacing in x? Or is this a question where you have some general nonlinear function, where you do know the function (i.e., it can be written down on paper) and you want to find some interval in x where the function deviates from linearity by the least amount? Of course, then you should recognize that no nonlinear function is truly linear, except over some short interval, where essentially any continuously differentiable function is locally linear everywhere.
Piecewise is irrelevant in any case, since piecewise is not a tool that can find anything.
But if you want to find some interval where a known differentiable nonlinear function is most linear, then you might just compute the second derivative of said function. Then search for the longest interval where that second derivative is less than some tolerance over the entire interval.
If what you have is a set of sampled points only from some relationship, do they have noise in them? So is the picture you show just some generic example you have cooked up? If you do have sampled data, then you can use the gradient functino to compute a second deritive estimate along the curve. Now again, just search for the longest interval where the absolute value of the second derivative is less than some tolerance.
Another possibility is to interpolate your data with a spline interpolant. Now take the second derivative of the cubic spline, which will now be a piecewise linear function. Again, find the longest interval where said second derivative function is less than some tolerance in absolute value.
If there is noise in your sampled data, then you need to smooth it first. In that case, a smoothing spline probably makes sense. Once you have the smoothing spline, again, differentiate twice.
In the end, I can see a zillion variations on what you might really have, and what you really need in the end.