用Pyx绘制括号 [英] Drawing braces with Pyx

查看:120
本文介绍了用Pyx绘制括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Pyx在两个任意点之间绘制一条支撑线?



它看起来像这样:





我沿着x轴绘制了此图以节省屏幕空间,但是为了沿y轴获得括号,只需交换x和y。最后,Pyx具有很多内置的路径绘制功能,也可以满足您的需求。


How can I draw a "braced" line between two arbitrary points with Pyx?

It would look something like this:

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

解决方案

You can draw pretty braces using sigmoidals. I don't have Pyx installed so I'll just plot these using matplotlib (pylab here). Here beta controls the sharpness of the curves in the 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()

I plotted this along the x-axis to save screen space, but to get braces along the y-axis just swap x and y. Finally, Pyx has plenty of path drawing functionality built-in which coould also work for your needs.

这篇关于用Pyx绘制括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆