Is this possible in python?

Markus von Ehr markus.vonehr at ipm.fhg.de
Thu Jul 11 02:45:48 EDT 2002


Hi,

an easy way is to use python and Tkinter.

you could subclass the canvas widget to create your line chart
like I did. Use a method to set the points, to redraw them,
to interpolate etc.
Instantiate Profile in your main program.

spline.py (implemented in python from Numerica Recipes)

example:


from Tkinter import *
import math
import spline
import Numeric

# defines

class Profile(Canvas):
    __CHART_MIN_X = 1
    __CHART_MAX_X = 790
    __CHART_MIN_Y = 10
    __CHART_MAX_Y = 110

    def __init__(self, parent = None, **kw):
        self.W = kw['W']
        self.H = kw['H']+20
        
        kw_corrected = {'height':self.H, 'width':self.W, 'bg':"white"}
        Canvas.__init__(self, parent, kw_corrected)
	self.root = parent

	self.__CHART_MAX_X = kw['W']
	self.__CHART_MAX_Y = kw['H']+self.__CHART_MIN_Y

        self.spec = []
        # initial spectrum values
        for i in range(512):
           
self.spec.append(int(math.sin(i/50.0)*((self.__CHART_MAX_Y-self.__CHART_MIN_Y)/2))+\
                             (self.__CHART_MAX_Y-self.__CHART_MIN_Y)/2)

        # draw chart grid
        for i in range(6):
            self.create_line(self.__CHART_MIN_X+1,
                            
self.__CHART_MIN_Y+i*((self.__CHART_MAX_Y-self.__CHART_MIN_Y)/5),
                             self.__CHART_MAX_X-2,
                            
self.__CHART_MIN_Y+i*((self.__CHART_MAX_Y-self.__CHART_MIN_Y)/5),
                             fill="black")

        for i in range(6):
           
self.create_line(self.__CHART_MIN_X+1+i*((self.__CHART_MAX_X-self.__CHART_MIN_X)/5),
                             self.__CHART_MIN_Y,
                            
self.__CHART_MIN_X+1+i*((self.__CHART_MAX_X-self.__CHART_MIN_X)/5),
                             self.__CHART_MAX_Y,
                             fill="black")
            
#        self.Redraw(1)

    def Redraw(self, factor):
        # delete old spectrum
        my_tuple = self.find_all()
	for item in range(len(my_tuple)):
            if self.itemcget(my_tuple[item], "fill") != "black":
                self.delete(my_tuple[item])

        # draw new spectrum
        for i in range(len(self.spec)-1):
            self.create_line(i+self.__CHART_MIN_X,
                             self.__CHART_MAX_Y -
int(self.spec[i]*factor),
                             i+1+self.__CHART_MIN_X,
                             self.__CHART_MAX_Y -
int(self.spec[i+1]*factor),
                             fill="red")
        
    def set(self, data):
        # set new spectrum
        self.spec = []
        for i in range(len(data)):
            self.spec.append(data[i])
    
    def value2screenY(self, y):
        return (self.__CHART_MAX_Y-y)-self.__CHART_MIN_Y




py thon schrieb:
> 
> I need a visual (gui) based app that can take a series of data point
> and plot them on a graph like a line chart.  Then I would like to
> reshape the curve created above by moving the data points with the
> mouse. (all using spline interpolation).  Then re-output the correct
> data  to a textfile.   I would like to know what part of this can
> python perform.
> 
> Thanks for your time



More information about the Python-list mailing list