如何将散景网格图中的多个图形保存到单独的 png 文件中?

问题描述 投票:0回答:0

我有一个由

bokeh
gridplot
生成的包含多个数字的 html 文件。

我的用例是:

  1. 我用眼睛检查每个图形,分别放大/缩小。
  2. 然后,我想单击一个按钮将所有图形保存到单独的 png 文件中。所以每个 png 文件是一个数字。

你能告诉我怎么做吗?

这里是一个示例代码,用于快速生成具有 2 个数字的网格图。

import numpy as np
from bokeh.io import save
from bokeh.layouts import gridplot
from bokeh.plotting import figure

x = np.linspace(0, 4 * np.pi, 100)
y = np.sin(x)

TOOLS = "pan,wheel_zoom,box_zoom,reset,save,box_select"

p1 = figure(title="Legend Example", tools=TOOLS)

p1.circle(x, y, legend_label="sin(x)")
p1.circle(x, 2 * y, legend_label="2*sin(x)", color="orange")
p1.circle(x, 3 * y, legend_label="3*sin(x)", color="green")

p1.legend.title = "Markers"

p2 = figure(title="Another Legend Example", tools=TOOLS)

p2.circle(x, y, legend_label="sin(x)")
p2.line(x, y, legend_label="sin(x)")

p2.line(
    x,
    2 * y,
    legend_label="2*sin(x)",
    line_dash=(4, 4),
    line_color="orange",
    line_width=2,
)

p2.square(x, 3 * y, legend_label="3*sin(x)", fill_color=None, line_color="green")
p2.line(x, 3 * y, legend_label="3*sin(x)", line_color="green")

p2.legend.title = "Lines"
p2.x_range = p1.x_range

save(gridplot([p1, p2], ncols=2, width=400, height=400))

谢谢。

python bokeh
© www.soinside.com 2019 - 2024. All rights reserved.