Commit d84799e0 authored by Matheus Müller's avatar Matheus Müller

Melhorias em Drag_rectangle2, operacional mas ainda sem remocao de pontos.

parent 167cdb61
from pylab import * from pylab import *
#xy0 = np.loadtxt('H2.py')
##################################################################################################### #####################################################################################################
# Funcoes que corrigem erros de arredondamento # Funcoes que corrigem erros de arredondamento
...@@ -32,7 +30,7 @@ def montaperfil( xy , step, modo): ...@@ -32,7 +30,7 @@ def montaperfil( xy , step, modo):
if modo == 'step': if modo == 'step':
for i in xy: for i in xy:
for j in arange (u, i[0], step): for j in arange (u, i[0], step):
if j>max(xy[:,0])/2 : if j>max(xy[:,0])/2 and j<=len(xy) :
concent[math.ceil(j/step)] = i[1] concent[math.ceil(j/step)] = i[1]
else : else :
concent[math.floor(j/step)] = i[1] concent[math.floor(j/step)] = i[1]
...@@ -41,16 +39,11 @@ def montaperfil( xy , step, modo): ...@@ -41,16 +39,11 @@ def montaperfil( xy , step, modo):
if modo == 'reta': if modo == 'reta':
for i in xy: for i in xy:
for j in arange (u, i[0], step): for j in arange (u, round(i[0],2), step):
if j>max(xy[:,0])/2 : concent[round(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u)
concent[math.ceil(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u) u = round(i[0],2)
else :
concent[math.floor(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u)
u = i[0]
yu = i[1] yu = i[1]
fix2(concent, profundidade) fix2(concent, profundidade)
print concent return concent
plot(profundidade, concent)
show()
...@@ -5,26 +5,43 @@ import matplotlib.pyplot as plt ...@@ -5,26 +5,43 @@ import matplotlib.pyplot as plt
from scipy.interpolate import interp1d from scipy.interpolate import interp1d
from scipy import interpolate from scipy import interpolate
from pylab import * from pylab import *
import Tkinter as tk from concentracao import *
listay = list() listay = list()
listax = list() listax = list()
drs = [] drs = []
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
recursivecontrol = 0 filename = "data.txt" #raw_input()
filename = raw_input() dxstep = 0.01
xx = arange(0,20, dxstep) # we'll create an x-axis from 0 to 2 pi
temp, = plot(xx,xx*0) # this is our initial plot, and does nothing
####################################################################################################### #######################################################################################################
# Add square # Add square
def add_square(x): def add_square(x, y):
global listay, drs, ax global listay, drs, ax
rect = ax.bar(x, 0.02, width=0.3) rect = ax.bar(x, 0.02, width=0.3)
for rec in rect: for rec in rect:
dr = DraggableRectangle(rec) dr = DraggableRectangle(rec)
dr.connect() dr.connect()
drs.append(dr) drs.append(dr)
rec.set_y(y-0.01)
listay.append(dr.rect.xy[1])
listax.append(dr.rect.xy[0])
dr.updateplot()
ylim([0,1])
xlim([0,20])
def add_immovable_square(x, y):
global listay, drs, ax
rect = ax.bar(x, 0.02, width=0.3)
for rec in rect:
dr = DraggableRectangle(rec)
drs.append(dr)
rec.set_y(y-0.01)
listay.append(dr.rect.xy[1]) listay.append(dr.rect.xy[1])
listax.append(dr.rect.xy[0]) listax.append(dr.rect.xy[0])
ylim([0,1]) ylim([0,1])
...@@ -52,7 +69,7 @@ class voidfunctions: ...@@ -52,7 +69,7 @@ class voidfunctions:
def on_a(self, event): def on_a(self, event):
if event.key=='a': if event.key=='a':
if not event.inaxes: return if not event.inaxes: return
add_square(float(event.xdata)) add_square(float(event.xdata), float(event.ydata))
# NAO FUNCIONA (DELETA TUDO) # NAO FUNCIONA (DELETA TUDO)
def on_r(self, event): def on_r(self, event):
...@@ -65,6 +82,7 @@ class voidfunctions: ...@@ -65,6 +82,7 @@ class voidfunctions:
self.rect.figure.canvas.mpl_disconnect(self.cida) self.rect.figure.canvas.mpl_disconnect(self.cida)
self.rect.figure.canvas.mpl_disconnect(self.cidr) self.rect.figure.canvas.mpl_disconnect(self.cidr)
#######################################################################################################
class DraggableRectangle: class DraggableRectangle:
lock = None # only one can be animated at a time lock = None # only one can be animated at a time
...@@ -72,7 +90,29 @@ class DraggableRectangle: ...@@ -72,7 +90,29 @@ class DraggableRectangle:
self.rect = rect self.rect = rect
self.press = None self.press = None
self.background = None self.background = None
self.rect.set_y(0.1)
def updateplot(self):
global listax, listay, temp, drs, dxstep
xytemp = list(drs)
for i in range(len(drs)):
xytemp[i] = drs[i].rect.xy
xytemp.sort(key=lambda s: s[0])
for i in range(len(listay)):
(listax[i], listay[i]) = xytemp[i]
data = open(filename , 'w')
for i in range(len(listay)):
print>>data, listax[i], listay[i]
data.close()
xydata = np.loadtxt(filename)
modo = 'step'
modo2 = 'reta'
temp.set_ydata(montaperfil( xydata, dxstep, modo)) # update the plot data
draw() # redraw the canvas
ylim([0,1])
xlim([0,20])
def connect(self): def connect(self):
'connect to all the events we need' 'connect to all the events we need'
...@@ -84,8 +124,6 @@ class DraggableRectangle: ...@@ -84,8 +124,6 @@ class DraggableRectangle:
'motion_notify_event', self.on_motion) 'motion_notify_event', self.on_motion)
def on_press(self, event): def on_press(self, event):
global drs, recursivecontrol
k = 0
'on button press we will see if the mouse is over us and store some data' 'on button press we will see if the mouse is over us and store some data'
if event.inaxes != self.rect.axes: return if event.inaxes != self.rect.axes: return
if DraggableRectangle.lock is not None: return if DraggableRectangle.lock is not None: return
...@@ -129,6 +167,8 @@ class DraggableRectangle: ...@@ -129,6 +167,8 @@ class DraggableRectangle:
# blit just the redrawn area # blit just the redrawn area
canvas.blit(axes.bbox) canvas.blit(axes.bbox)
#self.updateplot()
def on_release(self, event): def on_release(self, event):
'on release we reset the press data' 'on release we reset the press data'
if DraggableRectangle.lock is not self: return if DraggableRectangle.lock is not self: return
...@@ -142,14 +182,7 @@ class DraggableRectangle: ...@@ -142,14 +182,7 @@ class DraggableRectangle:
# redraw the full figure # redraw the full figure
self.rect.figure.canvas.draw() self.rect.figure.canvas.draw()
self.updateplot()
for i in range(len(listay)):
(listax[i], listay[i]) = drs[i].rect.xy
print listax, listay
data = open(filename , 'w')
for i in range(len(listay)):
print>>data, listax[i], listay[i]
def disconnect(self): def disconnect(self):
'disconnect all the stored connection ids' 'disconnect all the stored connection ids'
...@@ -157,11 +190,16 @@ class DraggableRectangle: ...@@ -157,11 +190,16 @@ class DraggableRectangle:
self.rect.figure.canvas.mpl_disconnect(self.cidrelease) self.rect.figure.canvas.mpl_disconnect(self.cidrelease)
self.rect.figure.canvas.mpl_disconnect(self.cidmotion) self.rect.figure.canvas.mpl_disconnect(self.cidmotion)
#######################################################################################################
voidrect = ax.bar(0, 0, width=0) voidrect = ax.bar(0, 0, width=0)
for void in voidrect: for void in voidrect:
vf = voidfunctions(void) vf = voidfunctions(void)
vf.connect() vf.connect()
add_square(2) add_immovable_square(0,0)
add_immovable_square(20,0)
#######################################################################################################
plt.show() plt.show()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment