Skip to content

Instantly share code, notes, and snippets.

@sungyongchoi
Last active March 23, 2016 03:19
Show Gist options
  • Save sungyongchoi/998a0fcb936a087c3cea to your computer and use it in GitHub Desktop.
Save sungyongchoi/998a0fcb936a087c3cea to your computer and use it in GitHub Desktop.
open button
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
import Tkinter as Tk
import tkFileDialog
import os
import csv
freqs = np.arange(2, 20, 3)
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2)
t = 0
s = 0
l, = plt.plot(t, s, lw=2)
plt.axis([-1, 30, -5,2])
class Index(object):
ind = 0
def open(self, event):
folder = tkFileDialog.askopenfilename() # show an "Open" dialog box and return the path to the selected file
x=[]
z=[]
f= open(folder)
#append values to list
for row in csv.reader(f):
x.append(row[0])
z.append(row[1])
l.set_xdata(x)
l.set_ydata(z)
plt.draw()
callback = Index()
axopen = plt.axes([0.7, 0.05, 0.1, 0.075])
bopen = Button(axopen, 'Open')
bopen.on_clicked(callback.open)
plt.show()
import Tkinter as Tk
import tkFileDialog
class Index(object):
ind = 0
def next(self, event):
def open(self, event):
filename = tkFileDialog.askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)
callback = Index()
axprev = plt.axes([0.7, 0.05, 0.1, 0.075])
axnext = plt.axes([0.81, 0.05, 0.1, 0.075])
bnext = Button(axnext, 'Next')
bnext.on_clicked(callback.next)
bopen = Button(axprev, 'Open')
bopen.on_clicked(callback.open)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
import Tkinter as Tk
import tkFileDialog
import os
import csv
import math
freqs = np.arange(2, 20, 3)
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.2)
t = 0
s = 0
l, = plt.plot(t, s, lw=2)
plt.axis([-1, 30, -5,2])
x=[]
z=[]
x_rotate=[]
z_rotate=[]
def rotate_vector(v, angle, anchor):
"""Rotate a vector `v` by the given angle, relative to the anchor point."""
x, y = v
x = float(x) - anchor[0]
y = float(y) - anchor[1]
# Here is a compiler optimization; inplace operators are slower than
# non-inplace operators like above. This function gets used a lot, so
# performance is critical.
cos_theta = math.cos(math.radians(angle))
sin_theta = math.sin(math.radians(angle))
nx = x*cos_theta - y*sin_theta
ny = x*sin_theta + y*cos_theta
nx = nx + anchor[0]
ny = ny + anchor[1]
return [nx, ny]
class Index(object):
ind = 0
def open(self, event):
folder = tkFileDialog.askopenfilename() # show an "Open" dialog box and return the path to the selected file
f= open(folder)
#append values to list
for row in csv.reader(f):
x.append(row[0])
z.append(row[1])
angle= 8
x_rotate.append(rotate_vector((row[0],row[1]),angle,(0,0))[0])
# rotate x to 8 angle
z_rotate.append(rotate_vector((row[0],row[1]),angle,(0,0))[1])
# rotate z to 8 angle
l.set_xdata(x)
l.set_ydata(z)
plt.draw()
def align(self, event):
plt.clf()
plt.plot(x_rotate, z_rotate, 'r.')
plt.axis([-1, 30, -5,2])
plt.draw()
callback = Index()
axopen = plt.axes([0.7, 0.05, 0.1, 0.075])
bopen = Button(axopen, 'Open')
bopen.on_clicked(callback.open)
axalign = plt.axes([0.81, 0.05, 0.1, 0.075])
balign = Button(axalign, 'Align')
balign.on_clicked(callback.align)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment