我使用了散景来生成400个图表并将其保存到我的Mac本地硬盘上的400个html文件(func azure functionapp fetch-app-settings <appName>
... file_1.html
)。
我用来生成图表并将其保存的代码示例位于
之下file_400.html
我需要逐个查看400个html文件,我只对每个图形的放大视图感兴趣,这意味着每个图形的最后100个点。请注意,每个图表中的曲线必须由我查看(由于我的专业知识),所以我不能使用人工智能之类的东西来查看图表。
我现在可以做的是:
import numpy as np
from bokeh.plotting import figure, output_file, save
p = figure(plot_width=400, plot_height=400)
x = np.arange(1, 1000) # all 400 graphs have the same x
y1 = np.arange(1, 1000)*2 # different file can have different y
p.line(x, y1, line_width=2)
output_file('file_1.html')
save(p)
这种方法非常耗时且无聊。
您有更好的方法来浏览所有这些文件吗?
一个首选功能是我可以在一个窗口中打开它们,它们会自动放大,我只需要点击键盘上bokeh
和left-arrow
的按钮即可浏览图表。
期待您的帮助和感谢!
答案 0 :(得分:1)
这实际上似乎是一个可以在本地运行的小型Bokeh服务器应用程序的完美用例。您可以将代码放在文件app.py
中,然后在命令行运行bokeh serve --show app.py
。
import numpy as np
from bokeh.io import curdoc
from bokeh.models import Button, ColumnDataSource, TextInput
from bokeh.layouts import widgetbox, row
from bokeh.plotting import figure
current = 0
x = np.linspace(0, 20, 500)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
plot = figure(x_range=(10,20), title="Plot 0")
plot.line('x', 'y', source=source)
def update_data(i):
global current
current = i
# compute new data or load from file, etc
source.data = dict(x=x, y = np.sin(x*(i+1)))
plot.title.text = "Plot %d" % i
def update_range(attr, old, new):
plot.x_range.start = float(start.value)
plot.x_range.end = float(end.value)
start = TextInput(title="start", value="10")
start.on_change('value', update_range)
end = TextInput(title="start", value="20")
end.on_change('value', update_range)
next = Button(label="next")
next.on_click(lambda: update_data(current+1))
prev = Button(label="prev")
prev.on_click(lambda: update_data(current-1))
curdoc().add_root(row(widgetbox(start, end, next, prev), plot))
这可以通过一些错误处理和一些额外的花里胡哨来改进,但希望能够证明。它产生以下交互式应用程序:
答案 1 :(得分:0)
好的,让我们看看我们如何做到这一点。我的第一个想法是,这可以通过硒来实现。我假设你以前没用过它。简而言之,它是一种以编程方式使用浏览器执行操作的方法。
让我们开始吧!安装python库
pip install selenium
你还需要安装geckodriver(在这个例子中我们将使用firefox)。如果您使用的是osx,可以使用brew安装。
brew install geckodriver
然后我们就可以开始编写脚本来打开400个标签了!它将打开您在本地拥有的所有数据。我会告诉你如何弄清楚如何缩放。 selenium的文档可以是found here ->
(该脚本使用python 3,而pathlib仅存在于python 3中)
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
html_path = Path.cwd()
browser = webdriver.Firefox()
for no in range(1, 400):
(ActionChains(browser).key_down(Keys.CONTROL)
.send_keys('t')
.key_up(Keys.CONTROL)
.perform())
file_path = html_path / 'file_1.html'
browser.get('file://' + str(file_path))