python - How to Plot realistic curves using Scipy -
my python program able plot graphs it's curves unrealistic.
for example :
how can smooth-en graph using scipy? have seen previous tutorials regarding matter tended use numpy , arange() features. since program doesn't derive points plotted numpy think it's features useless in scenario.
import tkinter tk import ttk import sympy import matplotlib.pyplot plt x = sympy.symbols('x') class interface(ttk.frame): def __init__(self,parent=none): ttk.frame.__init__(self,parent) self.parent = parent self.initui() def initui(self): self.x_from_1 = ttk.label(self.parent, text= ' x values should : ') self.x_from_2 = ttk.label(self.parent, text = ' : ') self.x_from_1_inp = ttk.entry(self.parent) self.x_from_2_inp = ttk.entry(self.parent) self.equation_label = ttk.label(self.parent,text = 'equation : ') self.equation = ttk.entry(self.parent) self.submit = ttk.button(self.parent,text='plot',command= self.plot) # grid allocations here self.x_from_1.grid(column=0,row=0) self.x_from_2.grid(column=5,row=0) self.x_from_1_inp.grid(column=1,row=0) self.x_from_2_inp.grid(column=10,row=0) self.equation_label.grid(column = 0,row=3) self.equation.grid(column=1,row=3,ipadx= 35) self.submit.grid(column=10,row=5) # grid allocations end here def plot(self): x_vals = range(int(self.x_from_1_inp.get()),int(self.x_from_2_inp.get())) eq = eval(self.equation.get()) self.prepare_table(x_vals,eq) plt.plot(x_vals,self.y_values) plt.grid(true) plt.show() def prepare_table(self,x_values,equation): y = [] in x_values: y.append(equation.subs(x,i)) self.y_values = y return self.y_values root = tk.tk() root.title('graphs') app = interface(root) app.mainloop()
use scipy.interpolate.interp1d: scipy.interpolate.interp1d
... scipy.interpolate import interp1d import numpy class interface(ttk.frame): .... def plot(self): x_vals = range(int(self.x_from_1_inp.get()),int(self.x_from_2_inp.get())) eq = eval(self.equation.get()) self.prepare_table(x_vals,eq) f = interp1d(x_vals, self.y_values, kind='cubic') x_new = numpy.linspace(x_vals[0], x_vals[-1], (x_vals[-1]-x_vals[0])*4) plt.plot(x_new, f(x_new)) plt.grid(true) plt.show()
Comments
Post a Comment