def graph_it(self): '''prepares plot and calls PlotPopup''' to_plot = [] for item in self.ids['graph_space'].children[1:]: if isinstance(item, PlotCheckBox): if item.active: to_plot.append(item.obj) if (self.ids['graph_space'].children[0].active and self.plot_current['text']): orig = main().request_info('tuple_list') text = self.plot_current['text'] new_plot_obj = {} for plot_obj in self.plot_history: if orig == plot_obj['orig'] and text == plot_obj['text']: new_plot_obj = plot_obj.copy() #if plot_obj is still empty, get a new one. if not new_plot_obj: new_plot_obj = main().request_plot_object() self.plot_history = np.insert(self.plot_history, 0, new_plot_obj) if new_plot_obj not in to_plot: to_plot.insert(0, new_plot_obj) self.update() if to_plot: #plotter = PlotPopup() #plotter.add_list(to_plot) #plotter.open() #for line in plt.figure(1).axes[0].lines: # if line.get_label() == 'hi': # print line.get_ydata() # line.set_zorder(10) plt.figure(1) plt.clf() plt.ion() plt.ylabel('pct of the total occurences') plt.xlabel('values') pt_style = itertools_cycle(['o', '<', '>', 'v', 's', 'p', '*', 'h', 'H','+', 'x', 'D', 'd']) colors = itertools_cycle(['b', 'g', 'y', 'r', 'c', 'm', 'y', 'k']) for obj in to_plot: style = '{}-{}'.format(next(pt_style), next(colors)) plt.plot(obj['pts'][0], obj['pts'][1], style, label=obj['text']) plt.legend(loc='best') plt.show()
def render(self, context): if not hasattr(context, 'cycle_nodes'): context.cycle_nodes = {} if self.cyclevars is None: name = 'CycleNode_%s' % self.variable_name if not name in context.cycle_nodes: raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) node = context.cycle_nodes[name] else: if self not in context.cycle_nodes: context.cycle_nodes[self] = itertools_cycle(self.cyclevars) if self.variable_name: # saving self also under a discoverable name name = 'CycleNode_%s' % self.variable_name context.cycle_nodes[name] = self node = self cycle_iter = context.cycle_nodes[node] value = cycle_iter.next().resolve(context) if self.variable_name and self.cyclevars is not None: context[self.variable_name] = value return '' else: return value
def render_tag(self, context, values, varname): if self not in context.render_context: context.render_context[self] = itertools_cycle(values) cycle_iter = context.render_context[self] value = cycle_iter.next().resolve(context) if varname: context[varname] = value return value
def render(self, context): if self not in context.render_context: context.render_context[self] = itertools_cycle(self.cyclevars) cycle_iter = context.render_context[self] value = cycle_iter.next().resolve(context) if self.variable_name: context[self.variable_name] = value return value
def render(self, context): if self not in context.render_context: # First time the node is rendered in template context.render_context[self] = itertools_cycle(context[self.list_variable]) cycle_iter = context.render_context[self] value = cycle_iter.next() if self.template_variable: context[self.template_variable] = value return ''
def render(self, context): if context.has_key("forloop"): if not context.get(self): context[self] = True self.cycle_iter = itertools_cycle(self.cyclevars) value = self.cycle_iter.next() value = Variable(value).resolve(context) if self.variable_name: context[self.variable_name] = value return value
def render(self, context): if self not in context.render_context: # First time the node is rendered in template context.render_context[self] = itertools_cycle(self.cyclevars) cycle_iter = context.render_context[self] value = next(cycle_iter).resolve(context) if self.variable_name: context[self.variable_name] = value if self.silent: return '' return render_value_in_context(value, context)
def render(self, context): if self not in context.render_context: # First time the node is rendered in template context.render_context[self] = itertools_cycle(self.cyclevars) if self.silent: return "" cycle_iter = context.render_context[self] value = cycle_iter.next().resolve(context) if self.variable_name: context[self.variable_name] = value return value
def make_graph(self): '''makes a graph and plots''' colors = itertools_cycle([ [0.2, 1.0, 0, 1], [1, 0, 0.2, 1], [0, 0.2, 1, 1], [0.6, 0, 0.8, 1], [1, 0.4, 0.2, 1], [1, 0.8, 0, 1], [0.8, 1.0, 0.1, 1] ]) x_range = [] y_range = [] y_ticks = [0.05, 0.1, 0.2, 0.5, 1, 5, 10] x_ticks = [1, 2, 5, 10, 20, 30, 50, 100, 200, 300, 500, 1000, 2000, 5000] for plot_obj in self._plot_list: plot_obj['color'] = next(colors) self.ids['graph'].add_plot(MeshLinePlot(points=plot_obj['pts'], color=plot_obj['color'])) if x_range: x_range[0] = min(x_range[0], plot_obj['x_min']) x_range[1] = max(x_range[1], plot_obj['x_max']) else: x_range = [plot_obj['x_min'], plot_obj['x_max']] if y_range: y_range[1] = max(y_range[1], plot_obj['y_max']) else: y_range = [0, plot_obj['y_max']] x_tick_num = (x_range[1]-x_range[0])/9. for tick in x_ticks: if x_tick_num < tick: x_tick_num = tick break y_tick_num = (y_range[1]-y_range[0])/20. for tick in y_ticks: if y_tick_num < tick: y_tick_num = tick break x_range[0] -= x_range[0] % x_tick_num current = self.ids['graph'].font_size factor = 1. if x_tick_num > 49: factor = 0.75 if x_tick_num > 99: factor = 0.66 if x_tick_num > 499: factor = 0.5 self.ids['graph'].font_size = int(factor * current) self.ids['graph'].x_ticks_major = x_tick_num self.ids['graph'].y_ticks_major = y_tick_num self.ids['graph'].xmin = x_range[0] self.ids['graph'].ymin = -y_tick_num self.ids['graph'].xmax = x_range[1] self.ids['graph'].ymax = y_range[1]
def make_legend(self): '''created the dropdown menu that's called by 'legend' button''' colors = itertools_cycle(self._color_list) for text, pts in self._plot_list: btn = ListButton(text=text, size_hint=(None, None), height=80, lst=pts, color=next(colors), valign='middle') btn.bind(on_release=self.legend.select) self.legend.add_widget(btn) self.legend.on_select = self.flash_plot self.ids['legend'].bind(on_release=self.legend.open) self.ids['legend'].bind(on_release=self.resize) self.legend.bind(on_dismiss=self.shrink_button)
def render(self, context): if self not in context.render_context: context.render_context[self] = itertools_cycle(self.cycle_values) cycle_iter = context.render_context[self] try: conditional_variable_value = self.conditional_variable.resolve(context) if self.passes_condition(conditional_variable_value): value = next(cycle_iter).resolve(context) self.last_cycle_value = value else: if self.last_cycle_value is None: self.last_cycle_value = next(cycle_iter).resolve(context) value = self.last_cycle_value return render_value_in_context(value, context) except template.VariableDoesNotExist: # fail silently... return
def make_graph(self): '''makes a graph and plots''' colors = itertools_cycle(self._color_list) y_ticks = [0.05, 0.1, 0.2, 0.5, 1, 5, 10] x_ticks = [1, 2, 5, 10, 20, 30, 50, 100, 200, 300, 500, 1000, 2000, 5000] for text_pts in self._plot_list: color_ = next(colors) self.ids['graph'].add_plot(MeshLinePlot(points=text_pts[1], color=color_)) #get numbers for graph ticks x_tick_num = (self.x_range[1]-self.x_range[0])/9. for tick in x_ticks: if x_tick_num < tick: x_tick_num = tick break y_tick_num = (self.y_range[1]-self.y_range[0])/20. for tick in y_ticks: if y_tick_num < tick: y_tick_num = tick break self.x_range[0] -= self.x_range[0] % x_tick_num #adjust font size according to tick numbers current = self.ids['graph'].font_size font_factor = 1. if x_tick_num > 49: font_factor = 0.75 if x_tick_num > 99: font_factor = 0.66 if x_tick_num > 499: font_factor = 0.5 self.ids['graph'].font_size = int(font_factor * current) self.ids['graph'].x_ticks_major = x_tick_num self.ids['graph'].y_ticks_major = y_tick_num self.ids['graph'].xmin = self.x_range[0] self.ids['graph'].ymin = -y_tick_num self.ids['graph'].xmax = self.x_range[1] self.ids['graph'].ymax = self.y_range[1]
def __init__(self, **kwargs): super(NumberInput, self).__init__(**kwargs) pad = StackLayout(orientation='lr-tb') texts = itertools_cycle(['+', '-', '=']) for digit in range(1, 10): pad.add_widget(Button(text=str(digit), size_hint=(0.29, 0.25), on_press=self.add_digit)) if digit % 3 == 0: pad.add_widget(Button(text=next(texts), size_hint=(0.1, 0.25), on_press=self.plus_minus)) pad.add_widget(Button(text='<-BS-', size_hint=(0.29, 0.25), on_press=self.back_space)) pad.add_widget(Button(text='0', size_hint=(0.29, 0.25), on_press=self.add_digit)) pad.add_widget(Button(text='ENT', size_hint=(0.39, 0.25), on_press=self.enter_val)) self.num_pad = Popup(title='', content=pad, size_hint=(0.8, 0.5), pos_hint={'x':0.1, 'y':0}) self.text = '' self.background_color = (0.4, 0.2, 1.0, 0.8) self.bind(on_release=self.open_pad) self.to_add = 0 self.sign = 1
def reset(self, context): context.render_context[self] = itertools_cycle(self.cyclevars)
def reset(self, context): """ Reset the cycle iteration back to the beginning. """ context.render_context[self] = itertools_cycle(self.cyclevars)
def __init__(self, cyclevars, variable_name=None): self.cycle_iter = itertools_cycle([Variable(v) for v in cyclevars]) self.variable_name = variable_name
def __init__(self, cyclevars, variable_name=None): self.cycle_iter = itertools_cycle(cyclevars) self.variable_name = variable_name
def __init__(self, cyclevars, variable_name=None): self.cyclevars = cyclevars self.cycle_iter = itertools_cycle(cyclevars) self.variable_name = variable_name