HTMatplotLib
Bar
Line
Pie
Scatter
Multi-Bar
Multi-Line
About
Contact
Bar Chart with Multiple Data
Please Select The Bar Chart Style.
Vertical Bar Chart
Horizontal Bar Chart
Submit
Copy URL
import numpy as np import matplotlib.pyplot as plt def my_function(*args, **kwargs): SelectInput = Element('SelectInput').element.value SelectInput = int(SelectInput) N = Element('quantity').element.value text = Element('test-input').element.value text_2 = Element('test-input-2').element.value text_3 = Element('test-input-3').element.value text_4 = Element('test-input-4').element.value text_5 = Element('test-input-5').element.value data_1 = Element('wow_10').element.value data_2 = Element('wow_20').element.value data_3 = Element('wow_30').element.value data_4 = Element('wow_40').element.value data_5 = Element('wow_50').element.value data_6 = Element('wow_60').element.value data_7 = Element('wow_70').element.value data_8 = Element('wow_80').element.value data_9 = Element('wow_90').element.value data_10 = Element('wow_100').element.value data_1 = list(map(int, data_1.split())) data_2 = list(map(int, data_2.split())) data_3 = list(map(int, data_3.split())) data_4 = list(map(int, data_4.split())) data_5 = list(map(int, data_5.split())) data_6 = list(map(int, data_6.split())) data_7 = list(map(int, data_7.split())) data_8 = list(map(int, data_8.split())) data_9 = list(map(int, data_9.split())) data_10 = list(map(int, data_10.split())) input_l = text_2 list_l = input_l.split() input_x = text list_x = input_x.split() ind = np.arange(len(list_x)) intN = int(N) width = 1 / (intN + 1) Element('test-output').element.innerText = list_l Element('test-output-1').element.innerText = list_x Element('test-output-2').element.innerText = text_3 Element('test-output-3').element.innerText = text_4 Element('test-output-4').element.innerText = text_5 fig,ax = plt.subplots() ind_1 = ind + width * (0 - (intN - 1) / 2) ind_2 = ind + width * (1 - (intN - 1) / 2) ind_3 = ind + width * (2 - (intN - 1) / 2) ind_4 = ind + width * (3 - (intN - 1) / 2) ind_5 = ind + width * (4 - (intN - 1) / 2) ind_6 = ind + width * (5 - (intN - 1) / 2) ind_7 = ind + width * (6 - (intN - 1) / 2) ind_8 = ind + width * (7 - (intN - 1) / 2) ind_9 = ind + width * (8 - (intN - 1) / 2) ind_10 = ind + width * (9 - (intN - 1) / 2) if SelectInput == 1: for j in range(intN): j = j+1 a = "data_%s" %(j) b = "ax.bar(ind_%s, "%(j) c = ", width)" z = b+a+c exec(z) title = text_3 plt.title(title) xlabel = text_4 plt.xlabel(xlabel) ylabel = text_5 plt.ylabel(ylabel) ax.set_xticks(ind) ax.set_xticklabels(list_x) ax.legend(list_l) plt.show() fig buffer = io.BytesIO() plt.savefig(buffer, format='png') buffer.seek(0) image_data = buffer.getvalue() base64_image = base64.b64encode(image_data).decode('utf-8') image_url = f'data:image/png;base64,{base64_image}' Element('quad').element.innerText = image_url if SelectInput == 2: for j in range(intN): j = j+1 a = "data_%s" %(j) b = "ax.barh(ind_%s, "%(j) c = ", width)" z = b+a+c exec(z) title = text_3 plt.title(title) xlabel = text_5 plt.xlabel(xlabel) ylabel = text_4 plt.ylabel(ylabel) ax.set_yticks(ind) ax.set_yticklabels(list_x) ax.legend(list_l) plt.show() fig buffer = io.BytesIO() plt.savefig(buffer, format='png', bbox_inches='tight') buffer.seek(0) image_data = buffer.getvalue() base64_image = base64.b64encode(image_data).decode('utf-8') image_url = f'data:image/png;base64,{base64_image}' Element('quad').element.innerText = image_url