Как бы я использовал ползунок для построения конкретного файла .las в боке - и перезаписать текущий - PullRequest
1 голос
/ 26 сентября 2019

Хорошо, так как выше, я пытаюсь использовать bokeh для построения некоторых данных - я хочу загрузить около 300 файлов из папки на моем компьютере, а затем ползунок выбрать активный график - я хочу только текущий выбранныйсюжет показан.Т.е. я должен переместить ползунок в положение 30 и увидеть только этот график - затем переместиться в положение 200 и увидеть только этот график.

Я понимаю, что для этого мне нужно использовать функцию обратного вызова, но у меня нетмного удачи и в итоге получим не отвечающий и пустой график.

мой код на данный момент выглядит так:

#Includes

#Basic Includes
import numpy as np #Mathematical
import pandas as pd #Data Handling
import bokeh as bk #Plotting
#import ipywidgets as widgets #Interactable widgets
import pathlib #Access of local data path

#bokeh
from bokeh.plotting import figure, output_notebook, show, output_file
from bokeh.layouts import gridplot, column, grid, row
from bokeh.palettes import Viridis256, Plasma256
from bokeh.transform import linear_cmap
from bokeh.models import (ColumnDataSource, ColorBar, LinearColorMapper, LogColorMapper, CustomJS, BasicTicker, Title,
Slider)
from bokeh.io import output_file, show

#ipywidgets
#from ipywidgets import interact, interactive, fixed, IntSlider, interact_manual
#from IPython.display import display

#pathlib
from pathlib import Path

#Allow Graphical Output to notebook
output_notebook()

#Path setup - Path is identical to the folder where data files are stored however every '\' must become '\\'
data_path = Path('C:\\Users\\E252606\\Desktop\\Geothermal\\J39\\J39') #Folder Where Dataset files are located

# create list of all CSV's in working directory
filetype = '*.las' #This is the file extension, may be .csv or *.las or .txt
filenames = list(data_path.glob(filetype))
#print(filenames)
#filenames 
data = {}

#Initialise a variable to store a count of the total number of files
DataCount = 0

#Loop through each file and load it into a dataframe
for filename in filenames:
    data[filename.stem] = pd.read_csv(filename, skiprows=37,sep=" ",names=['Depth Metres', '°C'])  #create df from csv
    #Increment counter to return number of files
    DataCount = DataCount +1

    #Filter Data frame
    Strength = 20 #Select the strength of the filter to use
    data[filename.stem] = data[filename.stem].rolling(window= Strength).mean()

#Initial Plot Definition

#Define the tools to initialise in bokeh plot
Tools ="hover,crosshair,pan,wheel_zoom,zoom_in,zoom_out,box_zoom, reset, save, box_select,poly_select,lasso_select,"

ToolTips = [('Temperature (°C):', '@y'),
            ('Depth (m):' , '@x{0}')
           ]


#Define the figure to push graphs onto (Select title, toolbar location, x & y axis labels and dimensions of plot)
Output = figure(tools = Tools, toolbar_location = "above" , tooltips = ToolTips , title = 'Profile' ,
           x_axis_label='x', y_axis_label= 'y',
            width = 1000, height =600)

#Additional readablilty settings
Output.title.align = "left"
Output.title.text_font_size = "17px"

#Autohide Toolbar until hover
Output.toolbar.autohide = True    

full_source = ColumnDataSource(data= data[filename.stem])
source = ColumnDataSource(data= data[filename.stem])

Output.multi_line(xs = '°C' , ys = 'Depth Metres', source = source)

amp_slider = Slider(start=0, end=DataCount, value=0, step=1, title="File Select")

callback = CustomJS(args=dict(source = source, full_source = full_source, amp=amp_slider),
                    code="""

    const A = amp.value;
    const time = cb_obj.value;
    const '°C' = full_source.data['°C']
    const 'Depth Metres' = full_source.data['Depth Metres']

        for(i=0; i<full_lons.length; i++) {
        source.data['°C'][i] = °C[10].slice(0, time)
        source.data['Depth Metres'][10] = @Depth Metres[i].slice(0, time)
    }

    source.change.emit()
    """)

amp_slider.js_on_change('value', callback)
slider = Slider(start = 0, end = DataCount, value = 1, step = 1, callback = callback)
slider.js_on_change('value', callback)


layout = row(
    column(Output, slider),
)

output_file("slider.html", title="slider.py example")

show(layout)




...