So after the other answer and comment I really really hope you ment working with ListPlot. Otherwise im sad :D
-
So it's not an anwser with a pretty short code but it works well.
To uniformly distribute your points, we want the length between adjacent points to be constant. So we formulate:
$$l=\sqrt{(\Delta x)^2+(\Delta y)^2}$$
$$l=\sqrt{(x_1-x_2)^2+(1/x_1-1/x_2)^2}$$
Solving this for $x_2$ gives two solutions. One backward (the first) and one forward solution (represented by Root
).
So if we define a $l$ and a $y_{min,max}$-value
l = 1/5; (*length between points*)
yBorder = 2; (*max absolute y value*)
sol = x2 /. Solve[l == Sqrt[(x1 - x2)^2 + (1/x1 - 1/x2)^2], x2, Reals];
we could solve the points as long as they are in the range using Reap
and Sow
in a Do
from both sides starting by $x=3$ and $x=-3$:
xPoints = Reap[
Do[
x = 3*(-1)^(i + 1); Sow[x];
y = 1/x;
While[Abs[y] <= yBorder, x = N[sol[[i]] /. {x1 -> x}]; Sow[x];
y = 1/x];
, {i, 1, 2}]
][[2, 1]];
getting everything together and ploting it:
l = 1/5; (*length between points*)
yBorder = 2; (*max absolute y value*)
xBorder = 3;
sol = x2 /. Solve[l == Sqrt[(x1 - x2)^2 + (1/x1 - 1/x2)^2], x2, Reals];
xPoints = Reap[
Do[
x = xBorder*(-1)^(i + 1); Sow[x];
y = 1/x;
While[Abs[y] <= yBorder, x = N[sol[[i]] /. {x1 -> x}]; Sow[x];
y = 1/x];
, {i, 1, 2}]
][[2, 1]];
yPoints = 1/xPoints;
points = Transpose[{xPoints, yPoints}];
ListPlot[points]
Attention:
You should also take the AspectRatio
and PlotRange
into account, since it seems that for bigger $y$-values the distance between the adjacent points shrinks or grows which is not the case.
I've did it for you (which was more easier than i thought):
It uses the fact that we just need to stretch one of the coordinates to the PlotRange and AspectRatio:
$$l=\sqrt{(\Phi\cdot (y_{max}-y_{min})/(x_{max}-x_{min})\cdot\Delta x)^2+(\Delta y)^2}$$
Where $\Phi$ is the inverse AspectRatio which is by default the GoldenRatio
.
l = 1; (*length between points*)
yBorder = 10; (*max absolute y value*)
xBorder = 50;
sol = x2 /.
Solve[l ==
Sqrt[(yBorder/xBorder)^2*
GoldenRatio^2*(x1 - x2)^2 + (1/x1 - 1/x2)^2], x2, Reals];
xPoints = Reap[
Do[
x = xBorder*(-1)^(i + 1); Sow[x];
y = 1/x;
While[Abs[y] <= yBorder, x = N[sol[[i]] /. {x1 -> x}]; Sow[x];
y = 1/x];
, {i, 1, 2}]
][[2, 1]];
yPoints = 1/xPoints;
points = Transpose[{xPoints, yPoints}];
ListPlot[points, PlotRange -> Full]
Plot
, right? $\endgroup$Plot[1/x, {x, -10, 10}, Mesh -> 30, MeshFunctions -> {"ArcLength"}, MeshStyle -> Red, PlotRange -> {-2, 2}, PlotStyle -> None]
work for you? $\endgroup$func[n_?NumericQ] := 1/n; Plot[func@n, {n, -1, 1}]
$\endgroup$