Einbinden einer BLT time axis
Verfasst: Freitag 17. September 2004, 12:10
Hallo,
habe ein umheimlich nettes Package gefunden, welches uns erlaubt Daten über der Zeit mehrkanalig in einer tkinter-Umgebung darzsutellen, ausserdem kann es die Graphiken auch als .PS exportieren.
Infos leider etwas kanpp auf
http://wiki.tcl.tk/3551.
Ich wollte die X- Achse nun als Echtzeit darstellen, habe auch ein Bsp. auf
http://wiki.tcl.tk/3551 gefunden.
Meine Frage bezieht sich nun darauf: wie kann ich diesen Programmschnipsel in ein bestehendes BLT Programm einbinden?
Habe das ganze Programm geschickt, da mich noch ein weiters Problem plagt: die Daten welche ich darstellen will bekomme ich als in einzelnen Speicherzellen, muss diese mit einem Timestamp
versehen, was auch wunderbar klappt. --> wie kann ich nun die einzelnen Y- Werte, also die einzelnen Koordinatenpaare in das Diagramm schreiben? Habe bereits etliches ausprobiert bin aber zu keinem vernüftigen Ergebnis gekommen. Evtl. hat schon jemand Erfahrungen mit so ähnlichen Problemchen. Freue mich über jede Hilfe.
Thankx
Stefan
habe ein umheimlich nettes Package gefunden, welches uns erlaubt Daten über der Zeit mehrkanalig in einer tkinter-Umgebung darzsutellen, ausserdem kann es die Graphiken auch als .PS exportieren.
Infos leider etwas kanpp auf
http://wiki.tcl.tk/3551.
Ich wollte die X- Achse nun als Echtzeit darstellen, habe auch ein Bsp. auf
http://wiki.tcl.tk/3551 gefunden.
Code: Alles auswählen
package require BLT
pack [blt::graph .g -width 10i]
# Proc passed as a callback to BLT to draw custom tick labels.
#
proc format_timeAxis_tick {win seconds} {
set hour [clock format $seconds -format "%H"]
regsub {^0*} $hour {} label
if {$hour} {
return $label
} else {
return "$label\n[string repeat { } $::nSpaces]\
[clock format $seconds -format "%d/%m"]"
}
}
# Construct a list of major tick positions in seconds - the
# month, year and the range of days can be varied to suit
# the application.
#
for {set day 20} {$day <= 23} {incr day} {
foreach hours {0 4 8 12 16 20} {
lappend majorticks [clock scan "3/$day/2001 $hours:00"]
}
}
lappend majorticks [clock scan "3/$day/2001 00:00"]
# Create the graph.
.g axis configure x \
-min [lindex $majorticks 0] \
-max [lindex $majorticks end] \
-title "Day" \
-majorticks $majorticks
# Need to do an update to display the graph before the
# distance can be measured.
update
# Measure the width of a day on the graph - the example
# dates need not be in the displayed range.
set dayFieldWidth [expr {
[.g axis transform x [clock scan 3/2/2001]] -
[.g axis transform x [clock scan 3/1/2001]]}]
# Work out how many spaces this corresponds to in the
# font for the tick labels.
set nSpaces [expr {$dayFieldWidth /
[font measure [.g axis cget x -tickfont] " "]}]
# Configure the axis to use the custom label command.
.g axis configure x -command format_timeAxis_tick
Code: Alles auswählen
from Tkinter import * # The Tk package
import Pmw # The Python MegaWidget package
import math # import the sin-function
master = Tk() # make a Tk root window
ncurves = 4 # draw 4 curves
npoints = 32 # use 32 points on each curve
if not Pmw.Blt.haveblt(master): # is Blt installed?
print("BLT is not installed!")
else:
vector_x = [] # vector for the x values in the curves
vector_y = []
for y in range(ncurves):
vector_y.append([]) # make vector_y as a list of lists (list of curves)
for x in range(npoints+1): # for each point...
vector_x.append(x*0.1) # compute x value
# fill vectors with cool graphs
for c in range(ncurves): # for each curve...
vector_y[c].append(math.sin(c*x*0.1)) # compute y value
g = Pmw.Blt.Graph(master) # make a new graph area
g.pack(expand=1, fill='both')
for c in range(ncurves): # for each curve...
curvename = 'sin(' + str(c) +'x)' # make a curvename
g.line_create(curvename, # and create the graph
xdata=tuple(vector_x), # with x-data,
ydata=tuple(vector_y[c]), # and y-data
symbol='') # ...and no markers
g.configure(title='Hello World of sine functions') # enter a title
master.mainloop() # ...and wait for input
Habe das ganze Programm geschickt, da mich noch ein weiters Problem plagt: die Daten welche ich darstellen will bekomme ich als in einzelnen Speicherzellen, muss diese mit einem Timestamp
Code: Alles auswählen
from time import gmtime, strftime
w = strftime("%a, %d %b %Y %H:%M:%S", gmtime())
print w
Thankx
Stefan