How to plot datas from many files?

Hello guys,

from datas coming to various directories, I want to plot and save them into their directories respectively.
I show many answers that explain to use reset_plot() after/before the function save or output_file.
https://discourse.bokeh.org/t/programmatically-creating-plots-in-a-loop/4056/6
https://stackoverflow.com/questions/37290219/bokeh-generating-graphs-in-a-loop-the-output-graphs-file-sizes-keep-increasin

Following the instructions above, they do not work for me.

I show you the minimal version of my problem below.
Let’s remind that i use the following version of python 3.6 and bokeh 2.2.0.

Thanks for your help.

def plot_data(data):
    output_file("dashboard_evolution_probs_mode_{}.html".format(
        ''.join(data.keys())))
    p = figure(plot_height = int(HEIGHT*1.0), 
                plot_width = int(WIDTH*1.5), 
                title = "test",
                x_axis_label = "abs", 
                y_axis_label = "ord", 
                x_axis_type = "linear",
                tools = TOOLS)
    source = ColumnDataSource(data)
    cpt = 0
    for key, value in data.items():
        p.circle(x="x", y=key, source=source, size=2, 
                 color="red", legend_label=key)
        p.line(x="x", y=key, source=source,line_color=Viridis256[cpt])
        cpt += 1
    save(p)
    reset_output()
    return p
    
    
def light_version_of_problem():
    data_xyz = {"x": np.random.uniform(low=0.5, high=13.3, size=(10,)),
                "y": np.random.uniform(low=0.5, high=5.3, size=(10,)),
                "z": np.random.uniform(low=0.5, high=10.3, size=(10,))
                }
    data_uvt = {"x": np.random.uniform(low=0.5, high=13.3, size=(10,)),
                "v": np.random.uniform(low=0.5, high=5.3, size=(10,)),
                "t": np.random.uniform(low=0.5, high=10.3, size=(10,))
                }
    for data in [data_xyz, data_uvt] :    
        plot_data(data)
        reset_output()

Hi @Willy_Zart you need to be more specific “does not work” does not say anything at all about what kind of problem you are seeing. E.g. No files are being generated, files are generated but are wrong some how, correct files are generated but the sizes keep increasing, etc. You need to state clearly and with details:

  • what is your expectation
  • what is actually happening and how it is different from expectation

Also, please make the minimal code above be complete so that we might actually be able to run it to investigate.

Hi,
thanks for your answer.

My goal is to generate and save html files into various directoiries.
In my initial post data_xyz and data_uvt come from directories x/y/z and u/v/t.
My expectation is, in one execution, to save html files, generated by datas (i.e. data_xyz and data_uvt), into their respective directories.

I have got the below error by running the function light_version_of_problem():

RuntimeError: Models must be owned by only a single document, BoxZoomTool(id='2098', ...) is already in a doc ```

You are re-using some components somewhere. I can’t see it in the partial snippet above. The best chance to be able to help you is if you provide a Minimal Reproducible Example that we can actually run to investigate.