Radiobutton does not work

ساخت وبلاگ

Vote count: 0

Hello I created a script python which allows to draw a polygon. Actually I have some points and what I want is this : I draw a polygon and the points which are inside are removed and the others are kept. But I created a Radiobutton to do the reverse that is to say the points which are outside are removed and the others are kept.

This is my code but it does not work because of Radiobutton :

import pylab as plt
import numpy as np
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
from matplotlib.widgets import Button
from matplotlib.widgets import RadioButtons
import os
import Tkinter as tk
from tkFileDialog import askopenfilename
from tkFileDialog import asksaveasfile
import ntpath
from Tkinter import Label
from Tkinter import Listbox
from Tkinter import END
import Tix
import scipy
a = np.array([1,2,3,4,5,6,7,8,9,10])
b = np.sin(a)
c = plt.plot(a,b,'r.')
cd = np.array([])
class Index(object): ind = 0
callback = Index()
choice = plt.axes([0.0, 0.92, 0.08, 0.07])
radio = RadioButtons(choice, ('IN', 'OUT'))
def sel(var): if var == "IN": return True elif var == "OUT": return False
class Canvas(object): def __init__(self,ax): self.ax = ax self.azer = radio.on_clicked(sel) self.path, = ax.plot([],[],'o-',lw=3) self.vert = [] self.x = [] self.y = [] self.mouse_button = {1: self._add_point, 2: self._delete_point, 3: self._close_polygon} def set_location(self,event): if event.inaxes: self.x = event.xdata self.y = event.ydata def _add_point(self): self.vert.append((self.x,self.y)) def _delete_point(self): if len(self.vert)>0: self.vert.pop() def _close_polygon(self): global a,b,c if radio.on_clicked(sel) == True: self.vert.append(self.vert[0]) myList=[] for i in range(0,a.size): myList.append(Point(float(a[i]),float(b[i]))) polygon = Polygon(self.vert) for i1 in range(0,len(a)): if not polygon.contains(myList[i1]): q = i1 a = np.delete(a,q-(len(myList)-len(a))) b = np.delete(b,q-(len(myList)-len(b))) c[0].remove() c = ax.plot(a,b, 'r.') for i2 in range(0,len(self.vert)): self.vert.pop() elif radio.on_clicked(sel) == False: self.vert.append(self.vert[0]) myList=[] for i in range(0,a.size): myList.append(Point(float(a[i]),float(b[i]))) polygon = Polygon(self.vert) for i1 in range(0,len(a)): if polygon.contains(myList[i1]): q = i1 a = np.delete(a,q-(len(myList)-len(a))) b = np.delete(b,q-(len(myList)-len(b))) c[0].remove() c = ax.plot(a,b, 'r.') for i2 in range(0,len(self.vert)): self.vert.pop() def update_path(self,event): if event.inaxes!=self.ax: return self.mouse_button[event.button]() x = [self.vert[k][0] for k in range(len(self.vert))] y = [self.vert[k][1] for k in range(len(self.vert))] self.path.set_data(x,y) plt.draw()
if __name__ == '__main__': fig = plt.figure(1,(8,8)) ax = fig.add_subplot(111) cnv = Canvas(ax) plt.connect('button_press_event',cnv.update_path) plt.connect('motion_notify_event',cnv.set_location)
plt.show()
asked 1 min ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 441 تاريخ : پنجشنبه 26 اسفند 1395 ساعت: 7:06