2

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.

silo
  • 21

2 Answers2

1

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

semola
  • 314
-1

Just use traditional polynomial interpolation:

enter image description here

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