誰かが私を正しい方向に向けてくれることを願っています。python datavisランドスケープは今や巨大になり、非常に多くのオプションがあるので、これを達成するための最良の方法が何であるかについて少し迷っています。
xarrayデータセットがあります(ただし、パンダのデータフレームまたはnumpy配列のリストである可能性があります)。
A、B、Cの3つの列があります。これらには40個のデータポイントが含まれています。
A対B +スケール* Cの散布図をプロットしたいと思います。ここで、スケールはインタラクティブスライダーから決定されます。
これのより高度なバージョンには、3つの列の別のセットを選択できるドロップダウンがありますが、それについては後で少し心配します。
これらすべての注意点は、他の人が使用できるようにオンラインでインタラクティブにしたいと思っていることです。
非常に多くのオプションがあるようです:
どんな考えやアドバイスも大歓迎です。
確かにたくさんの選択肢があり、何がベストかはわかりませんが、ボケ味をよく使って満足しています。以下の例で始めることができます。これを起動するには、スクリプトを保存するディレクトリでcmdを開き、「bokehservescript.py--show--allow-websocket-origin = *」を実行します。
from bokeh.plotting import figure
from bokeh.io import curdoc
from bokeh.models.widgets import Slider
from bokeh.models import Row,ColumnDataSource
#create the starting data
x=[0,1,2,3,4,5,6,7,8]
y_noise=[1,2,2.5,3,3.5,6,5,7,8]
slope=1 #set the starting value of the slope
intercept=0 #set the line to go through 0, you can change this later
y= [slope*i + intercept for i in x]#create the y data via a list comprehension
# create a plot
fig=figure() #create a figure
source=ColumnDataSource(dict(x=x, y=y)) #the data destined for the figure
fig.circle(x,y_noise)#add some datapoints to the plot
fig.line('x','y',source=source,color='red')#add a line to the figure
#create a slider and update the graph source data when it changes
def updateSlope(attrname, old, new):
print(str(new)+" is the new slider value")
y = [float(new)*i + intercept for i in x]
source.data = dict(x=x, y=y)
slider = Slider(title="slope", value=slope, start=0.0, end=2.0,step=0.1)
slider.on_change('value', updateSlope)
layout=Row(fig,slider)#put figure and slider next to eachother
curdoc().add_root(layout)#serve it via "bokeh serve slider.py --show --allow-websocket-origin=*"
allow-websocket-origin = *は、他のユーザーがサーバーにアクセスしてグラフを表示できるようにするためのものです。httpはhttp:// yourPCservername:5006 /になります(5006がデフォルトのボケポートです)。PCからサービスを提供したくない場合は、Herokuのようなクラウドサービスにサブスクライブできます:例。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加