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 *
#xy0 = np.loadtxt('H2.py')
#####################################################################################################
# Funcoes que corrigem erros de arredondamento
......@@ -32,7 +30,7 @@ def montaperfil( xy , step, modo):
if modo == 'step':
for i in xy:
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]
else :
concent[math.floor(j/step)] = i[1]
......@@ -41,16 +39,11 @@ def montaperfil( xy , step, modo):
if modo == 'reta':
for i in xy:
for j in arange (u, i[0], step):
if j>max(xy[:,0])/2 :
concent[math.ceil(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u)
else :
concent[math.floor(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u)
u = i[0]
for j in arange (u, round(i[0],2), step):
concent[round(j/step)] = yu + (j-u)*(i[1] - yu)/(i[0] - u)
u = round(i[0],2)
yu = i[1]
fix2(concent, profundidade)
print concent
plot(profundidade, concent)
show()
return concent
......@@ -5,26 +5,43 @@ import matplotlib.pyplot as plt
from scipy.interpolate import interp1d
from scipy import interpolate
from pylab import *
import Tkinter as tk
from concentracao import *
listay = list()
listax = list()
drs = []
fig = plt.figure()
ax = fig.add_subplot(111)
recursivecontrol = 0
filename = raw_input()
filename = "data.txt" #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
def add_square(x):
def add_square(x, y):
global listay, drs, ax
rect = ax.bar(x, 0.02, width=0.3)
for rec in rect:
dr = DraggableRectangle(rec)
dr.connect()
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])
listax.append(dr.rect.xy[0])
ylim([0,1])
......@@ -52,7 +69,7 @@ class voidfunctions:
def on_a(self, event):
if event.key=='a':
if not event.inaxes: return
add_square(float(event.xdata))
add_square(float(event.xdata), float(event.ydata))
# NAO FUNCIONA (DELETA TUDO)
def on_r(self, event):
......@@ -65,6 +82,7 @@ class voidfunctions:
self.rect.figure.canvas.mpl_disconnect(self.cida)
self.rect.figure.canvas.mpl_disconnect(self.cidr)
#######################################################################################################
class DraggableRectangle:
lock = None # only one can be animated at a time
......@@ -72,7 +90,29 @@ class DraggableRectangle:
self.rect = rect
self.press = 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):
'connect to all the events we need'
......@@ -84,8 +124,6 @@ class DraggableRectangle:
'motion_notify_event', self.on_motion)
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'
if event.inaxes != self.rect.axes: return
if DraggableRectangle.lock is not None: return
......@@ -129,6 +167,8 @@ class DraggableRectangle:
# blit just the redrawn area
canvas.blit(axes.bbox)
#self.updateplot()
def on_release(self, event):
'on release we reset the press data'
if DraggableRectangle.lock is not self: return
......@@ -142,14 +182,7 @@ class DraggableRectangle:
# redraw the full figure
self.rect.figure.canvas.draw()
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]
self.updateplot()
def disconnect(self):
'disconnect all the stored connection ids'
......@@ -157,11 +190,16 @@ class DraggableRectangle:
self.rect.figure.canvas.mpl_disconnect(self.cidrelease)
self.rect.figure.canvas.mpl_disconnect(self.cidmotion)
#######################################################################################################
voidrect = ax.bar(0, 0, width=0)
for void in voidrect:
vf = voidfunctions(void)
vf.connect()
add_square(2)
add_immovable_square(0,0)
add_immovable_square(20,0)
#######################################################################################################
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