Drawing curly braces with Pyx

How can I draw a “beveled” line between two arbitrary points with Pyx?

It will look something like this:

Curly Brace Example http://tof.canardpc.com/view/d16770a8-0fc6-4e9d-b43c-a11eaa09304d

+3
source share
2 answers

You can draw beautiful braces using sigmoidals . I don't have Pyx installed, so I just decompose them using matplotlib (pylab here). This betacontrols the clarity of the curves in braces.

import numpy as nx
import pylab as px


def half_brace(x, beta):
    x0, x1 = x[0], x[-1]
    y = 1/(1.+nx.exp(-1*beta*(x-x0))) + 1/(1.+nx.exp(-1*beta*(x-x1)))
    return y

xmax, xstep = 20, .01
xaxis = nx.arange(0, xmax/2, xstep)
y0 = half_brace(xaxis, 10.)
y = nx.concatenate((y0, y0[::-1]))

px.plot(nx.arange(0, xmax, xstep), y)
px.show()

enter image description here

x, , y, x y. , Pyx , .

+10

tom10 , .
[0,1], [0,1], .
. , , .

mid .
beta1 beta2 , ( ).
height ( y ).
x y. initial_divisions resolution_factor , x, .

import numpy as NP

def range_brace(x_min, x_max, mid=0.75, 
                beta1=50.0, beta2=100.0, height=1, 
                initial_divisions=11, resolution_factor=1.5):
    # determine x0 adaptively values using second derivitive
    # could be replaced with less snazzy:
    #   x0 = NP.arange(0, 0.5, .001)
    x0 = NP.array(())
    tmpx = NP.linspace(0, 0.5, initial_divisions)
    tmp = beta1**2 * (NP.exp(beta1*tmpx)) * (1-NP.exp(beta1*tmpx)) / NP.power((1+NP.exp(beta1*tmpx)),3)
    tmp += beta2**2 * (NP.exp(beta2*(tmpx-0.5))) * (1-NP.exp(beta2*(tmpx-0.5))) / NP.power((1+NP.exp(beta2*(tmpx-0.5))),3)
    for i in range(0, len(tmpx)-1):
        t = int(NP.ceil(resolution_factor*max(NP.abs(tmp[i:i+2]))/float(initial_divisions)))
        x0 = NP.append(x0, NP.linspace(tmpx[i],tmpx[i+1],t))
    x0 = NP.sort(NP.unique(x0)) # sort and remove dups
    # half brace using sum of two logistic functions
    y0 = mid*2*((1/(1.+NP.exp(-1*beta1*x0)))-0.5)
    y0 += (1-mid)*2*(1/(1.+NP.exp(-1*beta2*(x0-0.5))))
    # concat and scale x
    x = NP.concatenate((x0, 1-x0[::-1])) * float((x_max-x_min)) + x_min
    y = NP.concatenate((y0, y0[::-1])) * float(height)
    return (x,y)

:

import pylab as plt

fig = plt.figure()
ax = fig.add_subplot(111)

x,y = range_brace(0, 100)
ax.plot(x, y,'-')

plt.show()

Plot produced by example

PS: , clip_on=False plot .

+5

Source: https://habr.com/ru/post/1715353/


All Articles