If I want to plot the curve of a function, say 1/x, between 0.1 and 10, I can do it like this:
xx = np.linspace(0.1,10,1000)
yy = 1.0/xx
plt.plot(xx,yy)
The problem is that the spacing between points is not balanced along the curve. Specifically, at the left of the curve, where x<y, the points are very sparse (only about 10% of the points are there), and at the right of the curve, where x>y, the points are much denser (about 90% of the points are there, even though the curve is symmetric in both parts).
How can I create the arrays xx and yy (in general, not only for this particular function) such that the spacing between adjacent points is similar throughout the entire curve?
If the solution in the comments is not what you're looking for, here are a few others that choose abscissae such that the distances between points along the curve are constant. The last one is probably the most direct of the lot, but it requires some private functions, and those provate functions aren't available unless you have SciPy 1.12.
They all generate plots that are visually similar to this.
Using splines:
By finding events of an initial value problem...
Use numerical differentiation to get derivative of function
f, numerical integration to get arc length, and scalar rootfinding to get abscissa at desired arc lengths.(The private functions are not available in SciPy 1.11, but they will be available in SciPy 1.12, which you can get now with the nightly wheels. Note that these shouldn't be relied on for production code; they can be changed or removed without notice. Substitutes for
_differentiate,_tanhsinh, and_chandrupatlaarescipy.optimize.approx_fprime,scipy.integrate.quad, andscipy.optimize.root_scalar, but you'd need to use loops or applynp.vectorize.)