I am developing an application which takes input from user in .csv
form and plots the graph for the corresponding values using matplotlib
.
def plotgraph():
x = []
y = []
data = text.get("1.0", END)
sepFile = data.split('\n')
for plotPair in sepFile:
xAndY = plotPair.split(',')
if len(xAndY[0]) != 0 and len(xAndY[1]) != 0:
x.append(float(xAndY[0]))
y.append(float(xAndY[1]))
graph = Figure(figsize=(5,4), dpi=100)
a = graph.add_subplot(111)
a.plot(x,y)
a.set_xlabel('Velocity')
a.set_ylabel('Absorbance')
canvas = FigureCanvasTkAgg(graph, master=RightFrame)
canvas.show()
canvas.get_tk_widget().grid(column=2, row=1, rowspan=2, sticky=(N, S, E, W))
I want a similar function like this Matplotlib: draw a selection area in the shape of a rectangle with the mouse in Tkinter
which gives me the x0, x1, y0, y1
after the selection. I could make the already asked question make work & customize it according to my needs but unaware what I am doing mistake in __init__(self)
root = Tk()
class Annotate(object):
def __init__(self):
self.fig = mplfig.Figure(figsize=(1.5, 1.5))
self.ax = self.fig.add_subplot(111)
self.ax.plot([0,1,2,3,4],[0,8,9,5,3])
self.canvas = tkagg.FigureCanvasTkAgg(self.fig, master=root)
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
When I run this code I get a blank Tk window. Can anyone tell me what should I do & what am I doing mistake