Draw curved path between two points

628 Views Asked by At

I am plotting a ranked graph of popularity of characters in python.

To make it more aesthetically pleasing, I want to see what it looks like with "curved" lines linking sequential nodes together. After being unable to find this functionality, I thought of implementing it myself by fitting a cos function between two points. After messing around with cos functions however, I can't seem to manipulate it to look how I envisioned, which is actually something closer to a sigmoid function.

So I was wondering how I can construct a sigmoid function given two points or if there is a completely different and better way to approach this problem.

2

There are 2 best solutions below

0
On

Just use traditional polynomial interpolation:

enter image description here

(This is inverted because your axes are inverted... but that is easily fixed.)

0
On

The curve you refer to in your link above is simply a sigmoid: you can plot one as

import numpy as np, matplotlib.pyplot as plt

def conn_sig(x, y, beta=1):
    x_ = np.linspace(-5, 5)
    x_adj = np.linspace(*x)
    sig = 1/(1+np.exp(-x_*beta))
    sig = (sig-sig.min())/sig.max()
    sig_adj = sig *(y[1]-y[0]) + y[0]
    plt.plot(x_adj, sig_adj)


conn_sig(x=-1,1, y=(-1,3), beta=1)
plt.show()

Then you can adjust how pronounced the curvature is via the parameter beta.

Using the function above to connect a bunch of points results in something like this:

enter image description here