'''Whisker plot with quantiles indication (horizontal line shows the mean value)''' from vedo import np, settings, Axes, Brace, Line, Ribbon, show from vedo.pyplot import whisker
settings.default_font = 'Theemim'
# build some theoretical expectation to be shown as a grey band x = np.linspace(-1, 9, 100) y = x/5 + 0.2*np.sin(x) ye= y**2/5 + 0.1 # error on y line = Line(np.c_[x, y]) band = Ribbon(np.c_[x, y-ye], np.c_[x, y+ye]).c('black',0.1)
# create 5 whisker bars with some random data ws = [] for i in range(5): xval = i*2 # position along x axis data = xval/5 + 0.2*np.sin(xval) + np.random.randn(25) w = whisker(data, bc=i, s=0.5).x(xval) ws.append(w) # print(i, 'whisker:\n', w.info)
# build custom axes axes = Axes(xrange=[-1,9], yrange=[-3,5], htitle=':beta_c expression: change in time', xtitle=' ', ytitle='Level of :ET protein in \muM/l', x_values_and_labels=[(0,'ET^A\n at t=1h'), (4,'ET^B\n at t=2h'), (8,'ET^C\n at t=4h'), ], xlabel_size=0.02, xygrid=False, )
pythonCopy codex = np.linspace(-1, 9, 100) y = x/5 + 0.2*np.sin(x) ye= y**2/5 + 0.1 line = Line(np.c_[x, y]) band = Ribbon(np.c_[x, y-ye], np.c_[x, y+ye]).c('black',0.1)
這里 x 和 y 用于生成一條線,ye 代表 y 的誤差。Line 和 Ribbon 用于生成這個理論值的可視化表示。
打印Line和Ribbon圖層,我們可以看到構(gòu)建結(jié)果:
image-20231113235314087image-20231113235336419
注意這里的數(shù)據(jù)是隨機生成的。
代碼的核心部分是創(chuàng)建五個不同的箱線圖:
pythonCopy codews = [] for i in range(5): xval = i*2 data = xval/5 + 0.2*np.sin(xval) + np.random.randn(25) w = whisker(data, bc=i, s=0.5).x(xval) ws.append(w)