Introduction
This question is heavily connected with the related programming aspect around it (link), while the question might be better suited for this stack. However, if it is not suited for this stack just let me know and I will remove it.
Problem/Question
I am trying to calibrate data using a $n$-th degree polynomial using the numpy.polyfit function. The key purpose is to get the best fitting polynomial function that has one $x$-value for any given $y$-value but I am not that strongly versed in the underlying mathematics to understand how I would have to constrain my function to achieve this.
Therefore, the question is if there is some formula/rule that I can use, e.g. every subsequent term should be smaller than the previous term (random thought)?
Example
This would help prevent the problem that arises when a polynomial does have multiple $x$-values for a given $y$-value (first part of plot), namely that the calibrated data has two $y$-values for a given $x$-value (second part of plot). The calibrated $x$-values are acquired by doing new_X = f_polynomial(old_X) for all raw $x$ values.
Addendum
I am trying to constrain a polynomial so that the green variant is valid while the red variant is not valid (two $x$-values for a given $y$-value), with the example using a second third degree polynomial.


curve_fitto only try monotone functions. I will now return back to my comfort zone of the actual programming aspect of this, and thank you all for the time it took to figure out what I meant and point me in the right way (i'll accept an answer from either of you that mentions this). – Bas Jansen Jul 09 '18 at 14:16