Esempio n. 1
0
    def __init__(self, fig, ax):
        self.class_list = dict()  #diccionario con formato clase: color
        self.color_list = ['b', 'g', 'r', 'c', 'm', 'y', 'k']

        self.circle_list = [
        ]  #no debe ser un array de numpy, porque no sabemos que tamanno tendra a priori, y numpy es ineficiente para estos casos

        self.x0 = None
        self.y0 = None

        self.fig = fig
        self.ax = ax

        axbox = plt.axes([0.15, 0.02, 0.1, 0.07])
        self.class_box = TextBox(axbox, 'Clase Actual', initial='')
        self.class_box.on_submit(self.submit)

        axmbox = plt.axes([0.5, 0.02, 0.1, 0.07])
        self.method_box = TextBox(axmbox, 'Metodo', initial='lsq')
        self.method_box.on_submit(self.metodo)
        self.metodo_actual = None

        #axblda = plt.axes([0.6, 0.02, 0.2, 0.07])
        #blda = Button(axblda, 'Fisher LDA')

        self.cidpress = fig.canvas.mpl_connect('button_press_event',
                                               self.on_press)
        self.cidrelease = fig.canvas.mpl_connect('button_release_event',
                                                 self.on_release)
        self.cidmove = fig.canvas.mpl_connect('motion_notify_event',
                                              self.on_move)

        self.press_event = None
        self.current_circle = None
        self.moving_class = None
Esempio n. 2
0
def make_thresholds(up_th, lw_th):
    axbox_1 = plt.axes(
        [
            _submit_box["x"],
            _submit_box["y"],
            _submit_box["width"],
            _submit_box["height"],
        ]
    )
    text_box = TextBox(
        axbox_1, "Upper TH", initial=str(up_th), label_pad=_submit_box["label_pad"]
    )
    axbox_2 = plt.axes(
        [
            _submit_box["x"],
            _submit_box["y"] - _submit_box["separation"],
            _submit_box["width"],
            _submit_box["height"],
        ]
    )
    text_box_2 = TextBox(
        axbox_2, "Lower TH", initial=str(lw_th), label_pad=_submit_box["label_pad"]
    )

    return text_box, text_box_2
Esempio n. 3
0
    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()
Esempio n. 4
0
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()
Esempio n. 5
0
def button_click(event):
    datalist.clear()
    datalist.append(textbox1.text)
    datalist.append(textbox2.text)
    datalist.append(textbox3.text)
    textbox4 = TextBox(plt.axes([0.3, 0.5, 0.5, 0.075]),
                       'checksum',
                       initial=str(
                           bin(calculate_checksum(datalist)).replace('0b',
                                                                     '')))
    textbox5 = TextBox(plt.axes([0.3, 0.4, 0.5, 0.075]),
                       'sum',
                       initial=str(
                           bin(calculate_sum(datalist,
                                             int(textbox4.text,
                                                 2))).replace('0b', '')))
    content = " "
    if textbox5.text == "1111111111111111":
        content = "Check Successfully"
    else:
        content = "Check Failure"
    textbox6 = TextBox(plt.axes([0.3, 0.3, 0.5, 0.075]),
                       'result',
                       initial=content)
    plt.show()
Esempio n. 6
0
def textbox_btn_dropdown_setup(figure_class):
    """Sets up all the textboxes and buttons

    Parameters
    ==========
    figure_class (ROI_FigureClass)
        the roi_figureclass object

    Returns
    =======
    Nothing
    """
    # Starting the textboxes
    figure_class.vmin_tb = TextBox(figure_class.vmin_ax, 'vmin', initial='0')
    figure_class.vmax_tb = TextBox(figure_class.vmax_ax,
                                   'vmax',
                                   initial='1000')

    # Starting the buttons
    figure_class.rm_box_btn = Button(ax=figure_class.rm_box_btn_ax,
                                     label='Remove\nPrevious\nBox',
                                     color='teal',
                                     hovercolor='tomato')

    figure_class.contbtn = Button(ax=figure_class.contbtn_ax,
                                  label='Continue',
                                  color='teal',
                                  hovercolor='tomato')
    plt.draw()
Esempio n. 7
0
        def __init__(self, parent=None):
            self.parent = parent

            self.fig = plt.figure()

            self.run_ax = plt.axes([0.3, 0.9, 0.5, 0.1])
            self.run_selection = TextBox(self.run_ax,
                                         'Run',
                                         initial=str(self.parent.run),
                                         color='white',
                                         hovercolor='lightgrey')
            self.run_selection.on_submit(self.submit_run)

            self.entry_ax = plt.axes([0.3, 0.8, 0.5, 0.1])
            self.entry_selection = TextBox(self.entry_ax,
                                           'Entry',
                                           initial=str(self.parent.entry),
                                           color='white',
                                           hovercolor='lightgrey')
            self.entry_selection.on_submit(self.submit_entry)

            self.event_ax = plt.axes([0.3, 0.7, 0.5, 0.1])
            self.event_selection = TextBox(
                self.event_ax,
                'Event',
                initial=str(self.parent.event_analyzer.header.event_number),
                color='white',
                hovercolor='lightgrey')
            #self.event_selection.on_submit(self.parent.set_event)
            self.event_selection.on_submit(self.submit_event)

            self.set_values()

            plt.ion()
            self.fig.show()
def showUI():
    global ax
    fig, ax = plt.subplots()
    callback = Index()
    num_text = plt.text(0, 0, str(cur_idx))
    axtextbox_highlight = plt.axes([0.3, 0.05, 0.05, 0.075])
    axtextbox_showlabel = plt.axes([0.4, 0.05, 0.05, 0.075])
    axtextbox_merge = plt.axes([0.5, 0.05, 0.05, 0.075])
    axprev = plt.axes([0.7, 0.05, 0.1, 0.075])
    axnext = plt.axes([0.81, 0.05, 0.1, 0.075])

    textbox_highlight = TextBox(axtextbox_highlight, 'Student #')
    textbox_highlight.on_submit(callback.submitHighlight)

    textbox_showlabel = TextBox(axtextbox_showlabel, 'Node #')
    textbox_showlabel.on_submit(callback.submitShowLabel)

    textbox_merge = TextBox(axtextbox_merge, 'Merge')
    textbox_merge.on_submit(callback.submitMerge)
    bprev = Button(axprev, 'Previous')
    bprev.on_clicked(callback.prev)
    bnext = Button(axnext, 'Next')
    bnext.on_clicked(callback.next)

    plt.sca(ax)
    drawGraph("new")
    plt.show()
Esempio n. 9
0
def sap(ipAddress, port):
    rsa = SpectrumAnalyzer(host=ipAddress, port=port)
    rsa.connect()

    print(rsa.id)

    rsa.reset()
    rsa.write('format:data binary')

    rsa.write('spectrum:frequency:center {}'.format(rsa.cf))
    rsa.write('spectrum:frequency:span {}'.format(rsa.span))
    rsa.write('input:rlevel {}'.format(rsa.refLevel))

    rsa.write('initiate:continuous on')

    #rsa.write('trigger:status on')
    #rsa.write('trigger:event:source input')
    #rsa.write('trigger:event:input:level -50')

    axcf = plt.axes([0.15, 0.90, 0.05, 0.0375])
    tbcf = TextBox(axcf, 'Center Frequency (MHz)', initial=str(rsa.cf / 1e6))
    tbcf.on_submit(rsa.setCenterFrequencyMHz)

    axspan = plt.axes([0.26, 0.90, 0.05, 0.0375])
    tbspan = TextBox(axspan, 'Span (MHz)', initial=str(rsa.span / 1e6))
    tbspan.on_submit(rsa.setSpanMHz)

    axref = plt.axes([0.42, 0.90, 0.025, 0.0375])
    tbref = TextBox(axref, 'Reference Level (dBm)', initial=str(rsa.refLevel))
    tbref.on_submit(rsa.setReferenceLevel)

    axrun = plt.axes([0.7, 0.90, 0.1, 0.0375])
    axstop = plt.axes([0.81, 0.90, 0.1, 0.0375])
    brun = Button(axrun, 'Run')
    bstop = Button(axstop, 'Stop')
    brun.on_clicked(rsa.run)
    bstop.on_clicked(rsa.stop)

    anispectrum = FuncAnimation(figspectrum, updatespectrum, fargs=(rsa,), init_func=displayspectrum(rsa), interval=1, blit=False)
    anispectrogram = FuncAnimation(figspectrogram, updatespectrogram, fargs=(rsa,), init_func=displayspectrogram(rsa), interval=50, blit=False)
    anispectrum3d = FuncAnimation(figspectrum3d, updatespectrum3d, fargs=(rsa,), init_func=displayspectrum3d(rsa), interval=50, blit=False)

    figspectrum.canvas.mpl_connect('close_event', rsa.disconnect)

    rsa.readyToTerminate = False

    tspectrum = threading.Thread(target=updatespectrumdata, args=(rsa,))
    tspectrum.start()
    tspectrum3d = threading.Thread(target=updatespectrum3ddata, args=(rsa,50,))
    tspectrum3d.start()

    plt.show()

    rsa.readyToTerminate = True

    try:
        rsa.disconnect()
    except:
        pass
Esempio n. 10
0
 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))
Esempio n. 11
0
 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
Esempio n. 12
0
    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)
Esempio n. 13
0
    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)
Esempio n. 14
0
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 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
Esempio n. 16
0
    def __init__(self, xPos, yPos):
        self.xPos = xPos
        self.yPos = yPos
        self.posePublisher = rospy.Publisher("robot_pose",
                                             geometry_msgs.msg.Pose2D,
                                             queue_size=10)

        plt.ion()
        fig, axes = plt.subplots(nrows=2, figsize=(5, 2))
        text_box1 = TextBox(axes[0], 'X: ', initial=str(xPos))
        text_box1.on_submit(lambda text: self.sendChange(float(text), None))
        text_box2 = TextBox(axes[1], 'Y: ', initial=str(yPos))
        text_box2.on_submit(lambda text: self.sendChange(None, float(text)))
        plt.show(block=True)
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)
Esempio n. 18
0
def button_clicked(event):
    textbox4 = TextBox(plt.axes([0.3, 0.2, 0.5, 0.075]),
                       "result",
                       initial=flip(
                           calculate(calculate(textbox1.text, textbox2.text),
                                     textbox3.text)))
    plt.show()
Esempio n. 19
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
Esempio n. 20
0
 def __init__(self, m):
     self.methods = m
     self.fig, self.ax = plt.subplots()
     plt.subplots_adjust(bottom=0.2)
     tbbox = plt.axes([0.1, 0.05, 0.8, 0.075])
     self.tb = TextBox(tbbox, 'Шаги', initial='25')
     self.tb.on_submit(self.redraw)
Esempio n. 21
0
    def __init__(self, x_test):

        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

        p = self.current_slice

        # Let's set up image display gear
        self.fig, self.ax = plt.subplots(1, 1, figsize=(10, 8))
        self.fig.tight_layout()
        plt.subplots_adjust(bottom=0.20, top=0.9)

        self.ax.imshow(self.x_test[self.current_slice, :, :, 0])
        self.ax.set_title('Image No: ' + str(self.current_slice))

        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))
Esempio n. 22
0
 def __init__(self, x, y, info=None, x_pos=None, y_pos=None):
     plt.ion()
     self.fig, self.ax = plt.subplots()
     if info is not None:
         if not isinstance(info, str):
             info = str(info)
         self.fig.suptitle(info, fontsize=16)
     self.fig.set_figheight(6)
     self.fig.set_figwidth(10)
     plt.grid()
     plt.subplots_adjust(bottom=0.2)
     self.x = x
     self.y = y
     self._ind = None  # the active point index
     (self.basedata, ) = self.ax.plot(self.x, self.y)
     if (x_pos is None) or (y_pos is None):
         x_pos = []
         y_pos = []
     self._setup_positions(x_pos, y_pos)
     self.fig.canvas.mpl_connect("key_press_event", self.key_press_callback)
     self.fig.canvas.mpl_connect("button_release_event",
                                 self.button_release_callback)
     self.axbox = plt.axes([0.1, 0.05, 0.8, 0.1])
     self.text_box = TextBox(self.axbox,
                             "Delay [fs]",
                             initial="",
                             color="silver",
                             hovercolor="whitesmoke")
     self.text_box.on_submit(self.submit)
     self.text_box.on_text_change(self.text_change)
Esempio n. 23
0
    def __init__(self, im):
        """

        """
        self.fig = plt.figure()
        self.pos = []
        self.im = im
        self.eps = .01 * (self.im.axe_x[-1] - self.im.axe_x[0])
        self.pts = plt.plot([], marker="o", ls="none", mec='w', mfc='k')[0]
        self.axplot = plt.gca()
        self.ret_values = [None, None]
        self.real_dist = None
        self.real_unit = None
        # Display
        self.im.display(cmap=plt.cm.binary_r)
        plt.title("Scaling step:\n"
                  "Choose two points separated by a known distance.")
        # Connect click event on graph
        self.fig.canvas.mpl_connect('button_press_event', self.onclick)
        # Add ok button
        button_kwargs = {"color": "w", "hovercolor": [.5] * 3}
        self.axok = mpl.axes.Axes(self.fig, [0.88, 0.02, 0.1, 0.05])
        self.bnok = Button(self.axok, 'Done', **button_kwargs)
        self.bnok.on_clicked(self.done)  # set up the apsect
        self.fig.add_axes(self.axok)
        # Add text
        self.axtxt = mpl.axes.Axes(self.fig, [0.68, 0.02, 0.1, 0.05])
        self.btntxt = TextBox(self.axtxt, "Distance ('0.7mm' for example):",
                              "")
        self.btntxt.on_submit(self.on_submit)
        self.fig.add_axes(self.axtxt)
        # show the plot
        plt.show(block=True)
Esempio n. 24
0
    def addTextBox(self,
                   label,
                   submitHandler,
                   loc=(0.8, 0.0, 0.1, 0.07),
                   **kwargs):
        """Add a text box to the plot.

        Parameters
        ----------
        label : str
            Label for the button.
        submitHandler
            Submit handler to assign.
        loc : list(float), len 4
            Left, bottom, width, height.
        kwargs
            All other arguments passed to :class:`matplotlib.widgets.TextBox`.

        Returns
        -------
        matplotlotlib.widgets.TextBox

        """
        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
Esempio n. 25
0
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()
Esempio n. 26
0
def init_figure():
    fig = plt.figure()
    for y in range(3):
        for x in range(3):
            cell = fig.add_subplot(3, 3, xy_to_row(x, y) + 1)
            cell.tick_params(labelbottom=False, labelleft=False)
            cell.tick_params(bottom=False, left=False)
            viewText = (xy_to_row(x, y) + 1)
            cell.text(0.35, 0.35, viewText, size=40, color="blue")
            cells.append(cell)
    axbox = plt.axes([0.4, 0.01, 0.4, 0.075])
    global text_box
    text_box = TextBox(axbox, 'Trun ○ input number!')
    text_box.on_submit(submit)

    #先手の○を敵にする
    global nowTurn
    state = dizitize_state(board_status)
    action = np.argmax(qtable[state])
    canput = put_piece(action)
    nowTurn = (nowTurn + 1) % 2
    while canput == False:
        reward = -1000
        action, state = q_enemy(board_status, state, action, reward, 0)
        canput = put_piece(action)
        nowTurn = (nowTurn + 1) % 2
    plt.show()
Esempio n. 27
0
    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
Esempio n. 28
0
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)
Esempio n. 29
0
def TryTextBox2():
    #https://matplotlib.org/3.1.1/gallery/widgets/textbox.html
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.widgets import TextBox

    fig = plt.figure(figsize=[5, 5], constrained_layout=True)
    gs = GridSpec(2, 1, figure=fig)
    ax_plot = fig.add_subplot(gs[1, 0])

    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):
        t = np.arange(-2.0, 2.0, 0.001)
        print(text)
        ydata = eval(text)
        l.set_ydata(ydata)
        ax_plot.set_ylim(np.min(ydata), np.max(ydata))
        plt.draw()

    ax_gs = fig.add_subplot(gs[0, 0])
    textbox_raw_min = TextBox(ax_gs, "x min: ", initial="10")
    textbox_raw_min.on_submit(submit)

    #    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()

    return textbox_raw_min
Esempio n. 30
0
 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