def start_ui(): db.reset(settings.DATABASE) handler = BarChartHandler() source = HistSource(generator=SQLiteGenerator()) model = BarChart() model.configure(source, 'x', 'y', value_range_kw = { "low" : 0.0, "high" : 1.0 }, index_title = 'Value', value_title = 'Probability') view = View(Item('plot', editor = ComponentEditor(size=(400,400)), show_label = False), title = "Church", resizable = True, height = 400, width = 360) model.configure_traits(handler=handler, view=view)
def run_test(): """ Test class Barcharts: Basic bar chart, Grouped bar chart, Stacked bar chart. :return: No return. """ # Basic bar chart # a = BarChart([3, 5, 9, 2, 6, 15], ['python', 'js', 'java', 'C', 'C++', 'Css'], 'Programming language usage', 'vertical') # a.basic_bar_chart('Usage') # plt.show() # Grouped bar chart list_x = [[23, 5, 13, 4, 20, 40], [3, 5, 9, 2, 6, 15], [20, 19, 35, 27, 16, 15]] c = BarChart(list_x, ['a', 'b', 'c', 'd', 'e', 'f'], 'test', 'vertical') c.multi_bar(['var1', 'var2', 'var3'], 'objects_test') plt.show()
def reset(btn): if btn['text'] == "Start": global n new_data = random.randint(low, high, n) chosen_algorithms = [] for algorithm_showing in algorithms_showing: chosen_algorithms.append(algorithm_showing.algorithm) algorithm_showing.pack_forget() algorithms_showing.clear() for i in range(len(chosen_algorithms)): if i < 3: barchart = BarChart(chosen_algorithms[i], new_data.copy(), top_frame) else: barchart = BarChart(chosen_algorithms[i], new_data.copy(), middle_frame) barchart.pack() algorithms_showing.append(barchart)
def start_ui(): db.reset(settings.DATABASE) handler = BarChartHandler() source = HistSource(generator=SQLiteGenerator()) model = BarChart() model.configure(source, 'x', 'y', value_range_kw={ "low": 0.0, "high": 1.0 }, index_title='Value', value_title='Probability') view = View(Item('plot', editor=ComponentEditor(size=(400, 400)), show_label=False), title="Church", resizable=True, height=400, width=360) model.configure_traits(handler=handler, view=view)
def create(listbox, add_window, e1): global n n = int(e1.get()) data = random.randint(low, high, n) chosen_algorithms = [listbox.get(i) for i in listbox.curselection()] for algorithm_showing in algorithms_showing: algorithm_showing.pack_forget() algorithms_showing.clear() for i in range(len(chosen_algorithms)): alg = next(a for a in Algorithms if a.value == chosen_algorithms[i]) if i < 3: barchart = BarChart(alg, data.copy(), top_frame) else: barchart = BarChart(alg, data.copy(), middle_frame) barchart.pack() algorithms_showing.append(barchart) if len(algorithms_showing) > 0: btn["state"] = "active" reset_btn["state"] = "active" else: btn["state"] = "disabled" reset_btn["state"] = "disabled" add_window.destroy()
def graph(self, name, graphdir, proxy=None): from os.path import expanduser, isdir, join as joinpath from barchart import BarChart from matplotlib.numerix import Float, array, zeros import os, re, urllib from jobfile import crossproduct confgroups = self.jobfile.groups() ngroups = len(confgroups) skiplist = [ False ] * ngroups groupopts = [] baropts = [] groups = [] for i,group in enumerate(confgroups): if group.flags.graph_group: groupopts.append(group.subopts()) skiplist[i] = True elif group.flags.graph_bars: baropts.append(group.subopts()) skiplist[i] = True else: groups.append(group) has_group = bool(groupopts) if has_group: groupopts = [ group for group in crossproduct(groupopts) ] else: groupopts = [ None ] if baropts: baropts = [ bar for bar in crossproduct(baropts) ] else: raise AttributeError, 'No group selected for graph bars' directory = expanduser(graphdir) if not isdir(directory): os.mkdir(directory) html = file(joinpath(directory, '%s.html' % name), 'w') print >>html, '<html>' print >>html, '<title>Graphs for %s</title>' % name print >>html, '<body>' html.flush() for options in self.jobfile.options(groups): chart = BarChart(self) data = [ [ None ] * len(baropts) for i in xrange(len(groupopts)) ] enabled = False stacked = 0 for g,gopt in enumerate(groupopts): for b,bopt in enumerate(baropts): if gopt is None: gopt = [] job = self.jobfile.job(options + gopt + bopt) if not job: continue if proxy: import db proxy.dict['system'] = self.info[job.system] val = self.info.get(job, self.stat) if val is None: print 'stat "%s" for job "%s" not found' % \ (self.stat, job) if isinstance(val, (list, tuple)): if len(val) == 1: val = val[0] else: stacked = len(val) data[g][b] = val if stacked == 0: for i in xrange(len(groupopts)): for j in xrange(len(baropts)): if data[i][j] is None: data[i][j] = 0.0 else: for i in xrange(len(groupopts)): for j in xrange(len(baropts)): val = data[i][j] if val is None: data[i][j] = [ 0.0 ] * stacked elif len(val) != stacked: raise ValueError, "some stats stacked, some not" data = array(data) if data.sum() == 0: continue dim = len(data.shape) x = data.shape[0] xkeep = [ i for i in xrange(x) if data[i].sum() != 0 ] y = data.shape[1] ykeep = [ i for i in xrange(y) if data[:,i].sum() != 0 ] data = data.take(xkeep, axis=0) data = data.take(ykeep, axis=1) if not has_group: data = data.take([ 0 ], axis=0) chart.data = data bopts = [ baropts[i] for i in ykeep ] bdescs = [ ' '.join([o.desc for o in opt]) for opt in bopts] if has_group: gopts = [ groupopts[i] for i in xkeep ] gdescs = [ ' '.join([o.desc for o in opt]) for opt in gopts] if chart.legend is None: if stacked: try: chart.legend = self.info.rcategories except: chart.legend = [ str(i) for i in xrange(stacked) ] else: chart.legend = bdescs if chart.xticks is None: if has_group: chart.xticks = gdescs else: chart.xticks = [] chart.graph() names = [ opt.name for opt in options ] descs = [ opt.desc for opt in options ] if names[0] == 'run': names = names[1:] descs = descs[1:] basename = '%s-%s' % (name, ':'.join(names)) desc = ' '.join(descs) pngname = '%s.png' % basename psname = '%s.eps' % re.sub(':', '-', basename) epsname = '%s.ps' % re.sub(':', '-', basename) chart.savefig(joinpath(directory, pngname)) chart.savefig(joinpath(directory, epsname)) chart.savefig(joinpath(directory, psname)) html_name = urllib.quote(pngname) print >>html, '''%s<br><img src="%s"><br>''' % (desc, html_name) html.flush() print >>html, '</body>' print >>html, '</html>' html.close()
axis=1) # Join both dataframes and clean up date/time data merged_df = pd.merge(played_tracks_df, audio_features_df, how="left", on="track_id") def create_date_and_time(row): row['played_at'] = pd.to_datetime(row['played_at']) row['date_played'] = pd.to_datetime(row['played_at'].date()) row = row.rename({"played_at": "time_played"}) row['time_played'] = row['time_played'].time() return row merged_df = merged_df.apply(create_date_and_time, axis=1) # Create application layout bok_scatter = Scatter(merged_df) bok_bar = BarChart( merged_df.drop([ 'danceability', 'energy', 'loudness', 'speechiness', 'acousticness', 'instrumentalness', 'liveness', 'valence', 'tempo', 'duration_s' ], axis=1)) layout = column(bok_scatter.layout, bok_bar.layout) curdoc().add_root(layout)
def graph(self, name, graphdir, proxy=None): from os.path import expanduser, isdir, join as joinpath from barchart import BarChart from matplotlib.numerix import Float, array, zeros import os, re, urllib from jobfile import crossproduct confgroups = self.jobfile.groups() ngroups = len(confgroups) skiplist = [False] * ngroups groupopts = [] baropts = [] groups = [] for i, group in enumerate(confgroups): if group.flags.graph_group: groupopts.append(group.subopts()) skiplist[i] = True elif group.flags.graph_bars: baropts.append(group.subopts()) skiplist[i] = True else: groups.append(group) has_group = bool(groupopts) if has_group: groupopts = [group for group in crossproduct(groupopts)] else: groupopts = [None] if baropts: baropts = [bar for bar in crossproduct(baropts)] else: raise AttributeError, 'No group selected for graph bars' directory = expanduser(graphdir) if not isdir(directory): os.mkdir(directory) html = file(joinpath(directory, '%s.html' % name), 'w') print >> html, '<html>' print >> html, '<title>Graphs for %s</title>' % name print >> html, '<body>' html.flush() for options in self.jobfile.options(groups): chart = BarChart(self) data = [[None] * len(baropts) for i in xrange(len(groupopts))] enabled = False stacked = 0 for g, gopt in enumerate(groupopts): for b, bopt in enumerate(baropts): if gopt is None: gopt = [] job = self.jobfile.job(options + gopt + bopt) if not job: continue if proxy: import db proxy.dict['system'] = self.info[job.system] val = self.info.get(job, self.stat) if val is None: print 'stat "%s" for job "%s" not found' % \ (self.stat, job) if isinstance(val, (list, tuple)): if len(val) == 1: val = val[0] else: stacked = len(val) data[g][b] = val if stacked == 0: for i in xrange(len(groupopts)): for j in xrange(len(baropts)): if data[i][j] is None: data[i][j] = 0.0 else: for i in xrange(len(groupopts)): for j in xrange(len(baropts)): val = data[i][j] if val is None: data[i][j] = [0.0] * stacked elif len(val) != stacked: raise ValueError, "some stats stacked, some not" data = array(data) if data.sum() == 0: continue dim = len(data.shape) x = data.shape[0] xkeep = [i for i in xrange(x) if data[i].sum() != 0] y = data.shape[1] ykeep = [i for i in xrange(y) if data[:, i].sum() != 0] data = data.take(xkeep, axis=0) data = data.take(ykeep, axis=1) if not has_group: data = data.take([0], axis=0) chart.data = data bopts = [baropts[i] for i in ykeep] bdescs = [' '.join([o.desc for o in opt]) for opt in bopts] if has_group: gopts = [groupopts[i] for i in xkeep] gdescs = [' '.join([o.desc for o in opt]) for opt in gopts] if chart.legend is None: if stacked: try: chart.legend = self.info.rcategories except: chart.legend = [str(i) for i in xrange(stacked)] else: chart.legend = bdescs if chart.xticks is None: if has_group: chart.xticks = gdescs else: chart.xticks = [] chart.graph() names = [opt.name for opt in options] descs = [opt.desc for opt in options] if names[0] == 'run': names = names[1:] descs = descs[1:] basename = '%s-%s' % (name, ':'.join(names)) desc = ' '.join(descs) pngname = '%s.png' % basename psname = '%s.eps' % re.sub(':', '-', basename) epsname = '%s.ps' % re.sub(':', '-', basename) chart.savefig(joinpath(directory, pngname)) chart.savefig(joinpath(directory, epsname)) chart.savefig(joinpath(directory, psname)) html_name = urllib.quote(pngname) print >> html, '''%s<br><img src="%s"><br>''' % (desc, html_name) html.flush() print >> html, '</body>' print >> html, '</html>' html.close()
from app import app from sidebar import SideBar from table import PersonalTable from barchart import BarChart import dash_bootstrap_components as dbc app.layout = dbc.Row( [ dbc.Col([SideBar()], width=3, className="bg-dark"), # slider dbc.Col([BarChart(), PersonalTable()], width=9), # content ], className="vh-100") if __name__ == "__main__": app.run_server(debug=True)
pygame.init() screen = pygame.display.set_mode((1000, 600)) pygame.display.set_caption("Bar Chart Viewer") pygame.display.update() data1 = fruit_model.get_data() screen_rect = screen.get_rect() bc1_rect = pygame.Rect(screen_rect.x, screen_rect.y, screen_rect.width, screen_rect.height) # make it the full height again bc1 = BarChart(bc1_rect, data1) button = DataChangeButton("Change", pygame.Rect(10, screen_rect.height - 70, 150, 60), bc1) # display loop done = False while not done: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: done = True else: button.handle_event(event)