Как создать динамическую гистограмму с накоплением в режиме Bokeh с переменными входными и выходными данными ExcelPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как создать динамическую гистограмму с накоплением в режиме Bokeh с переменными входными и выходными данными Excel

Сообщение Anonymous »


I am currently working on a data visualisation project. I need to create a stacked bar chart using Bokeh. The data is sourced from an Excel file that is updated regularly and contains multiple inputs and outputs. The structure of the data can vary, meaning that the number of inputs and outputs can change. My aim is to ensure that the Bokeh chart can adapt to these changes automatically without requiring manual code adjustments. The stacked bar chart should be able to dynamically adjust to changes in the number of inputs and outputs in the Excel file. It should be capable of visualising various combinations of fixed inputs (e.g. input 1 fixed, input 2 fixed, input 3 variable) while displaying all corresponding outputs. Ideally, the solution would automatically read the Excel file, detect the structure of the inputs and outputs, and update the chart accordingly.

I have tried to visualize the stacked bar charts for a set scenario ( 2 Inputs and 3 Outputs). in the example excel file the data was stored in a scheme like this this:

Example Scheme:
Input_1 Input_2 Output_1 Output_2 Output_3 -1 1 200 400 100 0 1 300 600 200 1 2 100 550 300 -2 2 250 200 400
It worked for this static scenario:

import pandas as pd from bokeh.plotting import figure, output_file, show from bokeh.layouts import gridplot, row from bokeh.models import ColumnDataSource data_frame = pd.read_excel("example.xlsx") data_frame['Input_1'] = data_frame['Input_1'].astype(str) data_frame['Input_2'] = data_frame['Input_2'].astype(str) output_file("stacked_bar_charts.html") unique_input_1 = data_frame['Input_1'].unique() unique_input_2 = data_frame['Input_2'].unique() plots_for_input_1 = [] plots_for_input_2 = [] for value in unique_input_1: filtered_data = data_frame[data_frame["Input_1"] == value] filtered_data = filtered_data.sort_values(by='Input_2') source = ColumnDataSource(filtered_data) plot = figure(title=f"Input_1 = {value} fixed", x_range=filtered_data["Input_2"].unique(), height=300, width=500 ) plot.xaxis.axis_label = "Input_2" plot.vbar_stack(stackers=["Output_1", "Output_2", "Output_3"], x="Input_2", width=0.9, color=["orange", "gray", "brown"], source=source, legend_label=["Output 1", "Output 2", "Output 3"] ) plots_for_input_1.append(plot) for value in unique_input_2: filtered_data = data_frame[data_frame['Input_2'] == value] filtered_data = filtered_data.sort_values(by='Input_1') source = ColumnDataSource(filtered_data) plot = figure(title=f"Input_2 = {value} fixed", x_range=filtered_data["Input_1"].unique(), height=300, width=500 ) plot.xaxis.axis_label = "Input_1" plot.vbar_stack(stackers=["Output_1", "Output_2", "Output_3"], x="Input_1", width=0.9, color=["orange", "gray", "brown"], source=source, legend_label=["Output 1", "Output 2", "Output 3"] ) plots_for_input_2.append(plot) grid_for_input_1 = gridplot(plots_for_input_1, ncols=1) grid_for_input_2 = gridplot(plots_for_input_2, ncols=1) final_layout = row(grid_for_input_1, grid_for_input_2) show(final_layout) Here are output example pictures to show how I aim to visualize the data: bokeh example plot 1 bokeh example plot 2

I was unable to find a dynamic approach that works for changing inputs and outputs, such as varying two inputs while keeping the others constant and visualizing the impacts on all outputs through stacked bar charts. Additionally, the approach should efficiently adapt to data updates without requiring manual code adjustments for each new scenario.


Источник: https://stackoverflow.com/questions/780 ... -inputs-an
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»