3

matplotlib でステップ関数を作成するには、次のように記述します。

import matplotlib.pyplot as plt

x = [1,2,3,4] 
y = [0.002871972681775004, 0.00514787917410944, 
     0.00863476098280219, 0.012003316194034325]

plt.step(x, y)
plt.show()

Bokeh で同様のグラフを作成するにはどうすればよいですか?

4

3 に答える 3

5

Bokeh には、Stepバージョン のグリフが組み込まれてい0.12.11ます。

from bokeh.plotting import figure, output_file, show

output_file("line.html")

p = figure(plot_width=400, plot_height=400)

# add a steps renderer
p.step([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], line_width=2, mode="center")

show(p)

ここに画像の説明を入力

于 2018-07-24T21:44:04.723 に答える
0

line配列を手動で操作することで、それを行うことができます。軸のリストのインターリーブに注意してください。yまた、右と左の制限を達成するために、x 値をわずかに変更したい (と思います)。次のものを提供させてください。

from bokeh.plotting import figure
import numpy as np
f = figure()
#
# Example vectors (given):
x = [1,2,3,4]
y = [0.002871972681775004, 0.00514787917410944, 
     0.00863476098280219, 0.012003316194034325]
#
_midVals = np.diff(x)/2.0
xs = set(x[:-1]-_midVals).union(x[1:]+_midVals)
xl = list(xs)
xl.sort()
xx = xl[1:]+xl[:-1]
xx.sort()
yy = y+y
yy[::2] = y
yy[1::2] = y
#
# assert/print coordinates
assert len(xx)==len(yy)
for _p in zip(xx,yy):
    print _p
#
# Plot!
f.line(x=xx, y=yy)
show(f)

「健全性チェック」プリントの出口は次のようになります。

(0.5, 0.002871972681775004)
(1.5, 0.002871972681775004)
(1.5, 0.00514787917410944)
(2.5, 0.00514787917410944)
(2.5, 0.00863476098280219)
(3.5, 0.00863476098280219)
(3.5, 0.012003316194034325)
(4.5, 0.012003316194034325)

そしてプロット:

ボケ味のあるステッププロットの例

ここに到着した人の助けになることを願っています。

于 2016-01-19T22:42:42.583 に答える