나는 탐구하고자하는 커다란 데이터 세트를 가지고 있습니다. 그러나 나는 여러 플롯을 만들고 싶지 않습니다. 난 단지 x와 y 축에 사용 된 열을 대화식으로 변경할 수있는 단일 플롯을 원하며 플롯 자체가 업데이트됩니다.Bokeh가 플롯 할 대화식으로 열을 변경합니다.
나는이 스크립트를 브라우저에 제공하기 위해 Bokeh를 사용하여 Python/Bokeh를 사용하여이 작업을 수행하려고합니다. 그러나 음모를 업데이트하는 방법을 명확하게 알지 못합니다. 기본 데이터 소스가 변경된 예제가 많이 있지만이 작업을 원하지는 않습니다. 단지 어떤 컬럼이 플롯되고 있는지를 변경하고자합니다.
나는 아래에서 내가하고자하는 간단한 예제를 만들었습니다. 데이터 소스의 x 및 y 열을 선택하기 위해 두 개의 '선택'위젯을 사용합니다. 이것들은 'Line'글리프가 참조하는 열을 변경하려고하는 콜백을 가지고 있습니다. 그러나 이것은 작동하지 않는 것 같습니다. 모든 조언을 환영 할 것입니다.
import numpy as np
from bokeh.models import ColumnDataSource
from bokeh.plotting import Figure
from bokeh.models.widgets import Select,TextInput
from bokeh.models.glyphs import Line
from bokeh.models.layouts import HBox, VBox
from bokeh.io import curdoc
#==============================================================================
#%% Define some Data
#==============================================================================
N = 200
# Define the data to be used
x = np.linspace(0,4.*np.pi,N)
y = 3*np.cos(2*np.pi*x + np.pi*0.2)
z = 0.5*np.sin(2*np.pi*0.8*x + np.pi*0.4)
source = ColumnDataSource({'x':x,'cos':y,'sin':z})
#==============================================================================
#%% Layout
#==============================================================================
TOOLS = "box_select,lasso_select,help"
# create a new plot
plot = Figure(tools=TOOLS, title=None)
# Make a line and connect to data source
glyph = Line(x="x", y="cos", line_color="#F46D43", line_width=6, line_alpha=0.6)
plot.add_glyph(source, glyph)
# Add list boxes for selecting which columns to plot on the x and y axis
yaxis_select = Select(title="Y axis:", value="cos",
options=['x','cos','sin'])
xaxis_select = Select(title="X axis:", value="x",
options=['x','cos','sin'])
# Text input as a title
text = TextInput(title="title", value='my sine wave plotter')
# Layout widgets next to the plot
controls = VBox(text,yaxis_select,xaxis_select)
layout = HBox(controls,plot,width=800)
#==============================================================================
#%% Callbacks
#==============================================================================
# Put callbacks on the list boxes so that when they are changed the columns being
# plotted get changed.
def update_x_axis(attr, old, new):
# Change the column used for the x axis
glyph.x = xaxis_select.value
def update_y_axis(attr, old, new):
# Change the column used for the y axis
glyph.y = yaxis_select.value
yaxis_select.on_change('value', update_y_axis)
xaxis_select.on_change('value', update_x_axis)
#==============================================================================
#%% Add to document root
#==============================================================================
curdoc().add_root(layout)
curdoc().title = "Plotting app"
내가 바라고 있지만
불행히도, 이러한 특정 필드를 편집 완벽하게 파이썬 솔루션을 얻을 수 없다는 것을 나는 '같으면 Javascript로 내 손을 더럽힐 필요가 없습니다. 가능하면 파이썬에 머물고 싶습니다. 그러나 이것은 효과가있는 것으로 보이며 장애물 위에 나를 데려옵니다. 감사. – Redlegjed