def show_diagram(cursor, l, n, sel_type): sql = f""" SELECT iteration, pairwise_hamming_distribution_p, wild_type_hamming_distribution_p, ideal_hamming_distribution_p FROM task2_full_v1 WHERE L={l} AND N={n} AND sel_type='{sel_type}' AND run_id=0 ORDER BY iteration """ cursor.execute(sql) rows = cursor.fetchall() hist = np.array([row[1] for row in rows]) hist2 = np.array([row[2] for row in rows]) hist3 = np.array([row[3] for row in rows]) fig, (ax1, ax2, ax3) = plt.subplots(3, 1) barcollection = ax1.bar(range(l), hist[0]) barcollection2 = ax2.bar(range(l), hist2[0]) barcollection3 = ax3.bar(range(l), hist3[0]) axcut = plt.axes([0.1, 0.9, 0.1, 0.075]) tcut = TextBox(axcut, 'Iter:', '0') axcut2 = plt.axes([0.25, 0.9, 0.1, 0.06]) bcut = Button(axcut2, 'Run') def simData(): global it while it < len(rows): if not pause: it += 1 yield it def onClick(event): bcut.label.set_text('Stop') tcut.stop_typing() global pause pause ^= True def simPoints(it): if not pause: tcut.set_val(str(it)) for i, (b, b1, b2) in enumerate(zip(barcollection, barcollection2, barcollection3)): b.set_height(hist[it, i]) b1.set_height(hist2[it, i]) b2.set_height(hist3[it, i]) # return barcollection def change_it(event): global it it = int(event) tcut.on_submit(change_it) bcut.on_clicked(onClick) fig.set_size_inches(18.5, 10.5) ani = animation.FuncAnimation(fig, simPoints, simData, blit=False, interval=10, repeat=True) plt.show()
def __init__(self, points=[]): self.points = points self.cells = [] #Faces for halfedge data structure self.target_point = -1 self.fig = plt.figure() self.ax = self.fig.gca(projection="3d") plt.subplots_adjust(bottom=0.2) # self.cid_press = self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press) # self.cid_release = self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release) # self.cid_motion = self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion) axprepare = plt.axes([0.7, 0.05, 0.15, 0.075]) axsave = plt.axes([0.5, 0.05, 0.15, 0.075]) axopen = plt.axes([0.3, 0.05, 0.15, 0.075]) axfile_name = plt.axes([0.05, 0.05, 0.15, 0.075]) self.bprepare = Button(axprepare, 'Prepare stl') self.bprepare.on_clicked(self.prepare) self.bsave = Button(axsave, 'Save Points') self.bsave.on_clicked(self.save_points) self.bopen = Button(axopen, 'Open Points') self.bopen.on_clicked(self.open_points) self.points_file = "points.p" self.textbox_file_name = TextBox(axfile_name, "", initial="points.p") self.textbox_file_name.on_text_change(self.update_file_name) self.triangulate_vis()
def _init_plot(self): """ Initialize subplot objects and text box. """ fig, self.ax = plt.subplots(1, figsize=(8, 7)) plt.subplots_adjust(bottom=0.2) # Define button axes. self.axprev = plt.axes([0.54, 0.06, 0.12, 0.075]) self.axburst = plt.axes([0.67, 0.06, 0.13, 0.075]) self.axnext = plt.axes([0.81, 0.06, 0.12, 0.075]) # Define buttons and their actions. self.bnext = Button(self.axnext, 'Next (d)', hovercolor='g') self.bnext.on_clicked(self.next) self.bprev = Button(self.axprev, 'Previous (a)', hovercolor='g') self.bprev.on_clicked(self.prev) self.bmicroburst = Button(self.axburst, 'Microburst (m)', hovercolor='g') self.bmicroburst.on_clicked(self.append_remove_microburst) # Define the textbox axes. self.textbox = plt.axes([0.1, 0.05, 0.2, 0.075]) self.textbox.axis('off') # Define index box. self.axIdx = plt.axes([0.59, 0.01, 0.32, 0.04]) self.index_box = TextBox(self.axIdx, 'Index') self.index_box.on_submit(self.change_index) # Initialise button press fig.canvas.mpl_connect('key_press_event', self.key_press) return
def newGame(): test.startGame(True) df_segment_BTC = test.getChartData() #print(df_segment_BTC) #printBalances() plt.imshow(df_segment_BTC, cmap='hot') buyCom = plt.axes([0.9, 0.2, 0.1, 0.075]) buyButt = Button(buyCom, 'UP', color='red', hovercolor='green') buyButt.on_clicked(_buy) sellCom = plt.axes([0.9, 0.1, 0.1, 0.075]) sellButt = Button(sellCom, 'DOWN', color='red', hovercolor='green') sellButt.on_clicked(_sell) skipCom = plt.axes([0.9, 0.0, 0.1, 0.075]) skipButt = Button(skipCom, 'SKIP', color='red', hovercolor='green') skipButt.on_clicked(_skip) dollMeter = plt.axes([0.9, 0.7, 0.1, 0.075]) dollText = TextBox(dollMeter, 'Dollar', color='grey', initial=test.getCash()) btcMeter = plt.axes([0.9, 0.6, 0.1, 0.075]) btcMeter = TextBox(btcMeter, 'BTC', color='grey', initial=test.getBTC()) profitMeter = plt.axes([0.9, 0.5, 0.1, 0.075]) profitMeter = TextBox(profitMeter, 'Profit', color='grey', initial=test.getProfit()) plt.show()
def add_text_box(self, plt, rect, label, initial_value, callback): text_box = TextBox(plt.axes(rect), label, initial=initial_value, color=self.color, hovercolor=self.color) text_box.on_submit(callback) return text_box
def __init__(self, inp_ax, label, regexp, maxlen, decpoint=None): self.val = '' self.curpos = 0 self.pattern = re.compile(regexp) self.maxlen = maxlen self.decpoint = decpoint self.tb = TextBox(inp_ax, label) self.tb.on_text_change(self.tc_func)
def __create_grid_resolution_input(self) -> None: res_x, res_y = self._default_grid_resolution self._grid_x_axes_text_Box = plt.axes([0.35, 0.295, 0.15, 0.020]) self._grid_x_text_box: TextBox = TextBox(self._grid_x_axes_text_Box, "Res X: ", str(res_x)) self._grid_y_axes_text_Box = plt.axes([0.57, 0.295, 0.15, 0.020]) self._grid_y_text_box: TextBox = TextBox(self._grid_y_axes_text_Box, "Res Y: ", str(res_y))
def GUI(self, figsize=(13,12)): """ Creates the figure, lines, texts and annotations that will be manipulated, and also the interactive elements. """ # check if the GUI has already been initialized. If it is, just show the figure from the previous state if self.GUI_initialized: self.fig.show() else: # initializing GUI plot self.static_plot(show=False, figsize=figsize) self.spec_lim = self.init_spec_lim.copy() # adjust the main plots to make room for the sliders plt.subplots_adjust(bottom=self.bottom_adjust_val, top=self.top_adjust_val) # make sliders self.sliders_ax, self.sliders, current_right_column_pos = self.make_sliders() # make input textboxes for wavelength limits if current_right_column_pos[0] == self.right_x: right_edge = self.reset_button_arg[0] - 0.03 else: right_edge = self.right_x+self.width textbox_width = (right_edge-current_right_column_pos[0]-self.textbox_gap)/2 self.ax_spec_min = plt.axes([current_right_column_pos[0], current_right_column_pos[1], textbox_width, self.height]) self.spec_min_box = TextBox(self.ax_spec_min, r'$\lambda_{min}$', initial=self.init_spec_lim[0]) self.spec_min_box.on_submit(self.submit_min) self.ax_spec_max = plt.axes([current_right_column_pos[0]+textbox_width+self.textbox_gap, current_right_column_pos[1], textbox_width, self.height]) self.spec_max_box = TextBox(self.ax_spec_max, r'$\lambda_{max}$', initial=self.init_spec_lim[1]) self.spec_max_box.on_submit(self.submit_max) # register the update function with each slider for key in self.sliders.keys(): self.sliders[key].on_changed(self.update) # Create a `matplotlib.widgets.Button` to reset all sliders to initial values. self.resetax = plt.axes(self.reset_button_arg) self.reset_button = Button(self.resetax, 'Reset', color=self.slider_colors['misc'], hovercolor='0.975') self.reset_button.on_clicked(self.reset) # Create a `matplotlib.widgets.CheckButton` to toggle show or not additional plots self.moreplotsax = plt.axes(self.moreplots_check_arg) self.moreplots_check = CheckButtons(self.moreplotsax, ['additional plots']) self.moreplots_check.on_clicked(self.toggle_additional_plots) # additional plots toggle bool self.reset_additional_plots() plt.show() self.GUI_initialized = True
def name_from_user(self): def submit(text): plt.close() self.name = text axbox = plt.axes([0.1, 0.05, 0.8, 0.075]) text_box = TextBox(axbox, 'Name: ', initial="") text_box.on_submit(submit) plt.show()
class AltitudeGUI(): alt = [] ts = [] def __init__(self, master): master.columnconfigure(0,weight=1) master.rowconfigure(1,weight=1) self.master = master self.master.title("Attitude Tester") self.master.geometry('800x600') self.master.attributes("-zoomed", False) self.createGraph() self.plotGraph(1) self.master.bind("<Escape>", self.end_fullscreen) def end_fullscreen(self, event=None): self.state = False sys.exit() def createGraph(self): self.frame = Frame(self.master) self.frame.grid(column=0,row=1,columnspan=4, rowspan=3, sticky=N+W+E+S) self.f = Figure( figsize=(8, 7), dpi=80 ) self.ax0 = self.f.add_axes([.05, .625, .4, .35], frameon=False, label='X Orientation') self.ax0.set_xlabel( 'Time (ms)' ) self.ax0.set_ylabel( 'Degree' ) self.ax0.grid(color='r', linestyle='-', linewidth=2) self.boxAxis = self.f.add_axes([.075, .525, .325, .025]) #self.ax0.plot(np.max(np.random.rand(100,10)*10,axis=1),"r-") self.canvas = FigureCanvasTkAgg(self.f, master=self.frame) self.canvas.draw() self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=True) self.box = TextBox(boxAxis, "Altitude", initial="500") self.box.on_submit(self.plotGraph) # self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1) # self.toolbar.grid(column = 0, row = 2, columnspan=2) self.toolbar.update() def plotGraph(self, val): data = [] for i in range(0,len(self.ts)): data.append(eval(val)) comms.writeData("PA:" + val) self.line, = self.ax0.plot(self.ts,data) self.line.set_color("blue") self.addAltitudeData() self.l, = self.ax0.plot(self.ts, self.alt) self.l.set_color("black") self.canvas.draw() def addAltitudeData(self): self.alt = [] self.ts = [] for i in altitudeData: self.alt.append(i[0]) self.ts.append(i[1])
def init_control_zone(self): ######## Control Zone ######## contrl_ax = plt.axes([0.05, 0.05, 0.90, 0.27]) plt.text(0.035, 0.85, 'Control Zone') contrl_ax.set_xticks([]) contrl_ax.set_yticks([]) # slider ax_xbias = plt.axes([0.14, 0.21, 0.35, 0.03], facecolor=self.axcolor) ax_ybias = plt.axes([0.14, 0.16, 0.35, 0.03], facecolor=self.axcolor) self.s_xbias = Slider(ax_xbias, 'x_bias', 0.0, 5, valinit=self.x_bias) self.s_ybias = Slider(ax_ybias, 'y_bias', 0.0, 5, valinit=self.y_bias) # buttons aftax = plt.axes([0.8, 0.06, 0.1, 0.04]) self.reset_button = Button(aftax, 'RESET', color=self.axcolor, hovercolor='mistyrose') x_bias_dec_tax = plt.axes([0.57, 0.21, 0.03, 0.03]) self.x_bias_dec_button = Button(x_bias_dec_tax, '-', color=self.axcolor, hovercolor='mistyrose') x_bias_inc_tax = plt.axes([0.72, 0.21, 0.03, 0.03]) self.x_bias_inc_button = Button(x_bias_inc_tax, '+', color=self.axcolor, hovercolor='mistyrose') y_bias_dec_tax = plt.axes([0.57, 0.16, 0.03, 0.03]) self.y_bias_dec_button = Button(y_bias_dec_tax, '-', color=self.axcolor, hovercolor='mistyrose') y_bias_inc_tax = plt.axes([0.72, 0.16, 0.03, 0.03]) self.y_bias_inc_button = Button(y_bias_inc_tax, '+', color=self.axcolor, hovercolor='mistyrose') # textbox xtextax = plt.axes([0.61, 0.21, 0.1, 0.03]) ytextax = plt.axes([0.61, 0.16, 0.1, 0.03]) self.t_xbias = TextBox(xtextax, ' ', str(float('%.2f' % self.x_bias))) self.t_ybias = TextBox(ytextax, ' ', str(float('%.2f' % self.y_bias))) # radio button rax = plt.axes([0.78, 0.12, 0.15, 0.17], facecolor=self.axcolor) plt.title('AutoFit Algorithms', fontsize=8) self.algos = np.array(['Traverse', 'Mass Center', 'Slope']) self.radio = RadioButtons(rax, self.algos, active=0)
def view_dep_tree(reviews: List[Text], parsed_reviews: List[List[ParsedSentence]], review_index=0, sentence_index=0): """Pass reviews to viewer...""" matplotlib.use('Qt5Agg') plt.rcParams['keymap.save'].remove('s') fig, ax = plt.subplots() # prev/next buttons plt.subplots_adjust(bottom=0.2) title_ax = plt.axes([0.05, 0.95, 0.9, 0.05]) callback = TreeViewer(reviews=reviews, parsed_reviews=parsed_reviews, ax=ax, title_ax=title_ax, fig=fig, review_index=review_index, sentence_index=sentence_index) prev_left = 0.8 next_left = 0.9 button_bottom = 0.02 button_width = 0.06 button_height = 0.04 # prev / next ax_prev = plt.axes([prev_left, button_bottom, button_width, button_height]) ax_next = plt.axes([next_left, button_bottom, button_width, button_height]) b_next = Button(ax_next, 'Next') b_prev = Button(ax_prev, 'Previous') b_next._click = callback.next_image b_next.connect_event('button_press_event', callback.button_press) # save ax_save = plt.axes([0.5, button_bottom, button_width, button_height]) b_save = Button(ax_save, 'Save') b_save.on_clicked(callback.dump_labeled_reviews) # input ax_review_index = plt.axes( [0.1, button_bottom, button_width, button_height]) text_box = TextBox(ax_review_index, 'Review.Sentence', initial='0.0') text_box.on_submit(callback.input_review_index) # Maximise the plotting window try: mng = plt.get_current_fig_manager() mng.window.showMaximized() except AttributeError as e: logging.warning(e) plt.show()
def __init__(self, model, x_test, normalized=False, mean_img_x=[], mean_img_y=[]): MX = np.amax(np.abs(x_test)) self.x_test = x_test / MX self.idxB = 0 self.idxE = x_test.shape[0] self.current_slice = 0 self.model = model if (not isinstance(model, Model)): err_msg = 'res_browserR.res_browserR: the model passed in must be a Keras Model.' raise ValueError(err_msg) if (normalized == True and (len(mean_img_x) == 0 or len(mean_img_y) == 0)): err_msg1 = 'res_browserR.res_browserR: when working with normalized ' err_msg2 = 'data, the x and y means must be given.' raise ValueError(err_msg1 + err_msg2) self.normalized = normalized self.mean_img_x = mean_img_x self.mean_img_y = mean_img_y p = self.current_slice if (normalized == True): self.y_model = self.predict_from_demeaned(self.x_test, mean_img_x, mean_img_y, p) else: self.y_model = self.model.predict(self.x_test[p:(p + 1), :, :, :]) # Let's set up image display gear self.fig, self.ax = plt.subplots(1, 2, figsize=(10, 7)) self.fig.tight_layout() plt.subplots_adjust(bottom=0.20) self.ax[0].imshow(self.x_test[self.current_slice, :, :, 0]) self.ax[0].set_title('Input Image') self.ax[1].imshow(self.y_model[0, :, :, 0]) self.ax[1].set_title('Model Output') img_no_pos = plt.axes([0.48, 0.08, 0.04, 0.04]) # x, y, w, h label = 'Image No.: \nOut of ' + str(self.idxE) + ' ' self.img_tbox = TextBox(img_no_pos, label, initial=str(self.current_slice))
def _init_text_boxes(self): matplotlib.rcParams.update({'font.size': 6}) ax_delta = self.fig.add_axes([0.8, 0.5, 0.1, 0.05]) self.tb_delta = TextBox(ax_delta, 'Width', initial=str(self._delta)) self.tb_delta.on_submit(self._onsubmit_delta) ax_threshold = self.fig.add_axes([0.8, 0.4, 0.1, 0.05]) self.tb_threshold = TextBox(ax_threshold, 'Threshold%', initial=str(self._threshold_percent)) self.tb_threshold.on_submit(self._onsubmit_threshold_percent)
def _add_button(self, var, box): def _callback(text): try: self.__setattr__(var, float(text)) self._replot() except Exception as e: print(str(e)) tb = TextBox(plt.axes(box), var+' = ', initial=str(self.__getattribute__(var))) tb.on_submit(_callback) self.__setattr__('_tb_'+var, tb)
def make_widgets(self): self.textbox = TextBox(ax=plt.axes([0.2, 0.07, 0.1, 0.04]), label="ROI Name: ", initial='[roi_name]') btn_finish = Button(plt.axes([0.8, 0.07, 0.1, 0.04]), 'Finish') btn_finish.on_clicked(self.finish) btn_clear = Button(plt.axes([0.7, 0.07, 0.1, 0.04]), 'Clear') btn_clear.on_clicked(self.clear_rois) btn_add = Button(plt.axes([0.6, 0.07, 0.1, 0.04]), 'New ROI') btn_add.on_clicked(self.new_roi) btn_new = Button(plt.axes([0.5, 0.07, 0.1, 0.04]), 'New ROI Type') btn_new.on_clicked(self.new_roi_type) self.buttons.extend([btn_new, btn_add, btn_clear, btn_finish])
def idx_tb_setup(vmin_spot_ax, vmax_spot_ax): """Set up the index textboxes DEPRECIATED Returns ======= position 1 and position 2 textboxes for index values """ pos1_tb = TextBox(vmin_spot_ax, '', initial='0') pos2_tb = TextBox(vmax_spot_ax, '', initial='1') plt.draw() return pos1_tb, pos2_tb
def addTextBox(self, label, submitHandler, loc=(0.8, 0.0, 0.1, 0.07), **kwargs): self.checkInteractive() txtBoxAx = self.fig.add_axes(loc) txtBox = TextBox(txtBoxAx, label, **kwargs) txtBox.on_submit(lambda e: submitHandler(e, self)) self.txtBoxStore.append(txtBox) return txtBox
def add_notes_input(self): """Notes""" ax_text = self.fig.add_axes(cfg.position_text_input) self.text_box = TextBox(ax_text, color=cfg.text_box_color, hovercolor=cfg.text_box_color, label=cfg.textbox_title, initial=cfg.textbox_initial_text) self.text_box.label.update(dict(color=cfg.text_box_text_color, wrap=True, verticalalignment='top', horizontalalignment='left')) self.text_box.on_submit(self.save_user_notes)
def plot(self, x=0, y=0): self.hoffset = x self.voffset = y self.step = 1 axscale = plt.axes([0.25, 0.1, .55, 0.03], facecolor="green") self.slscale = Slider(axscale, 'Scale', 1, 2, valinit=1.2, valstep=0.01) self.slscale.on_changed(self.update) d = int(10**self.slscale.val) self.imsize = d self.ax = plt.axes([0.25, 0.2, .65, 0.7]) self.im = self.ax.imshow([[.0]], cmap=LinearSegmentedColormap.from_list( "thiscmap", colorlist[:max(self.code)], N=25)) self.cbar = self.ax.figure.colorbar(self.im, ax=self.ax) self.cbar.set_ticks(self.code) axright = plt.axes([0.14, 0.35, 0.04, 0.04]) axleft = plt.axes([0.06, 0.35, 0.04, 0.04]) axup = plt.axes([0.1, 0.39, 0.04, 0.04]) axdown = plt.axes([0.1, 0.31, 0.04, 0.04]) axstep = plt.axes([0.1, 0.35, 0.04, 0.04]) self.tbstep = TextBox(axstep, ' ', initial=' 1') self.tbstep.on_text_change(self.upstep) self.bright = Button(axright, r'$\rightarrow$', color="red", hovercolor='green') self.bleft = Button(axleft, r'$\leftarrow$', color="red", hovercolor='green') self.bup = Button(axup, r'$\uparrow$', color="red", hovercolor='green') self.bdown = Button(axdown, r'$\downarrow$', color="red", hovercolor='green') self.bright.on_clicked(self.fright) self.bleft.on_clicked(self.fleft) self.bup.on_clicked(self.fup) self.bdown.on_clicked(self.fdown) self.update(0)
class numeric_field: def __init__(self, inp_ax, label, regexp, maxlen, decpoint=None): self.val = '' self.curpos = 0 self.pattern = re.compile(regexp) self.maxlen = maxlen self.decpoint = decpoint self.tb = TextBox(inp_ax, label) self.tb.on_text_change(self.tc_func) def tc_func(self, inp): if (len(inp) > self.maxlen): self.tb.cursor_index = self.curpos self.tb.set_val(self.val) return if (self.decpoint and inp.find('.') < 0 and len(inp) > self.maxlen - 1): self.tb.cursor_index = self.curpos self.tb.set_val(self.val) return if (not self.pattern.match(inp)): self.tb.cursor_index = self.curpos self.tb.set_val(self.val) return self.val = inp self.curpos = self.tb.cursor_index
def create_parameter_gui(): global fig2 global boxes global parameters # new figure for parameters fig2, ax2 = plt.subplots() plt.axis('off') plt.subplots_adjust(top=0.5, left=0.1, right=0.2, bottom=0.4) axbox = plt.axes([0.4, 0.85, 0.2, 0.075]) text_box0 = TextBox(axbox, 'Segment (seconds)', str(parameters['seg_size_sec'])) axbox = plt.axes([0.4, 0.75, 0.2, 0.075]) text_box1 = TextBox(axbox, 'Segment shift (seconds)', str(parameters['seg_shft_sec'])) axbox = plt.axes([0.4, 0.65, 0.2, 0.075]) text_box2 = TextBox(axbox, 'Window size (seconds)', str(parameters['win_size_sec'])) axbox = plt.axes([0.4, 0.55, 0.2, 0.075]) text_box3 = TextBox(axbox, 'Window shift (seconds)', str(parameters['win_shft_sec'])) axbox = plt.axes([0.4, 0.45, 0.2, 0.075]) text_box4 = TextBox(axbox, 'Freq Conv. min Max (Hz)', str(parameters['freq_range']).strip('[').strip(']') ) axbox = plt.axes([0.4, 0.35, 0.2, 0.075]) text_box5 = TextBox(axbox, 'Spectr Pwr min Max (dB)', str(parameters['freq_color']).strip('[').strip(']')) axbox = plt.axes([0.4, 0.25, 0.2, 0.075]) text_box6 = TextBox(axbox, 'Freq Mod. min Max (Hz)', str(parameters['mfreq_range']).strip('[').strip(']')) axbox = plt.axes([0.4, 0.15, 0.2, 0.075]) text_box7 = TextBox(axbox, 'ModSpec Pwr min Max (dB)', str(parameters['mfreq_color']).strip('[').strip(']')) axbox = plt.axes([0.4, 0.05, 0.2, 0.075]) ok_button = Button(axbox, 'OK') boxes = [text_box0, text_box1, text_box2, text_box3, text_box4, text_box5, text_box6, text_box7, ok_button] ok_button.on_clicked(submit) return
def _set_buttons(self, enable_reset, enable_save, enable_io): reset_button = Button(plt.axes([0.51, 0.01, 0.1, 0.035]), 'Reset') # [0.88, 0.01, 0.1, 0.035] reset_button.label.set_color('r') reset_button.label.set_fontweight('bold') reset_button.on_clicked(self._reset) if enable_reset: reset_button.set_active(True) else: reset_button.set_active(False) reset_button.ax.set_visible(False) textbox = TextBox( plt.axes([0.2, 0.06, 0.6, 0.095]), 'I/O', initial='' ) # [0.12, 0.01, 0.65, 0.06] [0.05,0.92,0.8,0.07] [0.025, 0.885, 0.75, 0.05] textbox.label.set_fontweight('bold') textbox.on_submit(self._evaluate_message) if enable_io: textbox.set_active(True) else: textbox.set_active(False) textbox.ax.set_visible(False) save_button = Button(plt.axes([0.39, 0.01, 0.1, 0.035]), 'Save') # [0.77, 0.01, 0.1, 0.035] save_button.label.set_fontweight('bold') save_button.on_clicked(self._quicksave) if enable_save: save_button.set_active(True) else: save_button.set_active(False) save_button.ax.set_visible(False) self._widgetlist[self.fignum.index(plt.gcf().number)] = (reset_button, textbox, save_button) self._textbox = textbox
def init_page(self): fig.text(0.2, 0.8, 'SIMPLE HARMONIC MOTION', fontsize=50) amp_box_loc = plt.axes([0.4, 0.5, 0.2, 0.075]) self.amp_box = TextBox(amp_box_loc, 'Amplitude (A)', initial=str(self.amp)) tp_box_loc = plt.axes([0.4, 0.4, 0.2, 0.075]) self.tp_box = TextBox(tp_box_loc, 'Time Period (T)', initial=str(self.t_period)) dc_box_loc = plt.axes([0.4, 0.3, 0.2, 0.075]) self.dp_box = TextBox(dc_box_loc, 'Damping Constant (b)', initial=str(self.damp_cnst)) mass_box_loc = plt.axes([0.4, 0.2, 0.2, 0.075]) self.mass_box = TextBox(mass_box_loc, 'Mass of ball (m)', initial=str(self.mass)) bbox1 = plt.axes([0.45, 0.1, 0.1, 0.075]) self.button1 = Button(bbox1, "GO!") self.amp_box.on_submit(self.update_amp) self.tp_box.on_submit(self.update_t_period) self.dp_box.on_submit(self.update_damp_cnst) self.mass_box.on_submit(self.update_mass) self.button1.on_clicked(self.go) plt.draw()
def __init__(self, table): self.table = table self.ax = self.table.axes celld = table.get_celld() for key in celld.keys(): if key[0] > 0 and key[1] > -1: cell = celld[key] cell.set_picker(True) self.canvas = self.table.get_figure().canvas self.cid = self.canvas.mpl_connect('pick_event', self.on_pick) self.tba = self.ax.figure.add_axes([0, 0, .01, .01]) self.tba.set_visible(False) self.tb = TextBox(self.tba, '', initial="") self.cid2 = self.tb.on_submit(self.on_submit) self.currentcell = celld[(1, 0)]
def _slider_with_text(fig, pos, slider_str, val_min, val_max, val_default, padding): """ Creates a slider with text box given a position """ # Position params slider_left_offset = (pos[2] - 4 * padding) / 3 + 2 * padding slider_width = (pos[2] - 4 * padding) / 3 text_width = pos[2] - slider_left_offset - slider_width - 2 * padding # Slider slider_pos = [pos[0] + slider_left_offset, pos[1], slider_width, pos[3]] slider_axes = fig.add_axes(slider_pos) slider = Slider(slider_axes, slider_str, val_min, val_max, valinit=val_default, dragging=False) slider.valtext.set_visible(False) slider.label.set_fontsize(7) # Text text_pos = [ slider_pos[0] + slider_pos[2] + padding, slider_pos[1], text_width, pos[3] ] text_axes = fig.add_axes(text_pos) text = TextBox(text_axes, '') return slider, text
def set_textboxes(self): """Konfiguracja textboxy""" plt.text(0.87, 0.95, 'Ustaw prawdopodobienstwo', horizontalalignment='center', verticalalignment='center', transform=self.axes.transAxes) for i in range(10): axbox = plt.axes([0.95, 0.90 - i * 0.035, 0.03, 0.03]) text_box = TextBox(axbox, '', initial=str(self.pp_values[i]), hovercolor=self.colors[i]) text_box.on_submit(self.on_submit) self.text_boxes.append(text_box)
def __slider_with_text(fig, pos, slider_str, val_min, val_max, val_default, padding): # pylint: disable=too-many-arguments # Creates a slider with text box # Set position params slider_padding = 0.1 slider_text_width = (0.5 - 3 * padding) / 3 # Slider slider_pos = [ pos[0] + slider_padding + padding, pos[1], pos[2] - slider_padding - 3 * padding - slider_text_width, pos[3] ] slider_axes = fig.add_axes(slider_pos) slider = Slider(slider_axes, slider_str, val_min, val_max, valinit=val_default, dragging=False) slider.label.set_fontsize(7) slider.valtext.set_visible(False) # Text text_pos = [ slider_pos[0] + slider_pos[2] + padding, slider_pos[1], slider_text_width, pos[3] ] text_axes = fig.add_axes(text_pos) text = TextBox(text_axes, '') return (slider, text)
def clusterise_indicateur1(cat): X = [data_sal[i] for i in data_catm[cat]] Y = [data_pat[i] for i in data_catm[cat]] Z = [data_dep[i] for i in data_catm[cat]] moy_X = sum(X) / len(X) moy_Y = sum(Y) / len(Y) i_val = [] for i in range(len(X)): if Y[i] >= (max(Y) - ((max(Y) - moy_Y) / 10) - moy_Y) / (max(X) - min(X)) * (X[i] - min(X)) + moy_Y: if Z[i] >= X[i]: i_val.append(i) fig, ax = plt.subplots() ax1 = plt.subplot(121) ax2 = plt.subplot(122) ax1.scatter(X, Y, label="Non fraudeur") ax1.scatter([X[i] for i in i_val], [Y[i] for i in i_val], label="Fraudeur") ax1.set_xlabel("Revenu") ax1.set_ylabel("Patrimoine") ax1.legend() ax2.scatter(X, Z, label="Non fraudeur") ax2.scatter([X[i] for i in i_val], [Z[i] for i in i_val], label="Fraudeur") ax2.set_xlabel("Revenu") ax2.set_ylabel("Dépenses") axprev = plt.axes([0.53, 0.02, 0.14, 0.04]) TextBox(axprev, '', initial="{}/{} fraudeurs ({}%)".format( len(i_val), len(X), int(100 * len(i_val) / len(X)))) ax2.legend() fig.suptitle("Catégorie socio-professionnelle : {} – Indicateur 1".format( cat_list[cat])) plt.show()
def btn_clicked(e): number1 = int(textbox_1.text, 2) number2 = int(textbox_2.text, 2) number3 = int(textbox_3.text, 2) sum = bin(number1 + number2) # 检查溢出 if len(sum) > 18: sum = sum[3:19] sum = int(sum, 2) sum += 1 else: sum = sum[2:18] sum = int(sum, 2) print(bin(sum)) sum = bin(sum + number3) # 检查溢出 if len(sum) > 18: sum = sum[3:19] sum = int(sum, 2) sum += 1 else: sum = sum[2:18] sum = int(sum, 2) sum ^= 0xffff sum = bin(sum) print(sum) sum = sum[2:18] textbox_4 = TextBox(plt.axes([0.3, 0.1, 0.5, 0.075]), "checksum:", initial=sum)
Allowing text input with the Textbox widget. You can use the Textbox widget to let users provide any text that needs to be displayed, including formulas. You can use a submit button to create plots with the given input. """ import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import TextBox fig, ax = plt.subplots() plt.subplots_adjust(bottom=0.2) t = np.arange(-2.0, 2.0, 0.001) s = t ** 2 initial_text = "t ** 2" l, = plt.plot(t, s, lw=2) def submit(text): ydata = eval(text) l.set_ydata(ydata) ax.set_ylim(np.min(ydata), np.max(ydata)) plt.draw() axbox = plt.axes([0.1, 0.05, 0.8, 0.075]) text_box = TextBox(axbox, 'Evaluate', initial=initial_text) text_box.on_submit(submit) plt.show()