From: Aaron R. <aar...@gm...> - 2012-10-25 03:35:12
|
Hello all, I'm new to gnuplot and am hoping to get some advice on how to accomplish the goal I'm trying to get to and/or improvements to what I have so far. I'm trying to make a chart that shows windows of a given time duration and specific events, that occurred at a given time. The events are grouped by type and source. The specific example is trying to show which sensors in my house (motion, temperature, lights) are triggered over a given time. I'd like to be able to show a window that indicates the time a room is occupied and then samples from temperature in that room. There may be multiple windows for the same run that I want to have on the same line. So far, here is what I have: reset #use for saving image #set terminal png #set output 'plot.png' set title "Test plot" #data file with measurements DATAFILE='testdata' #clean up the borders set border 1 set xtics nomirror set ytics nomirror #unset ytics #create map to have all the events of a given type have same style stylemap(string) = (string eq 'TEMPMEASUREMENT' ? 1: \ string eq 'MOTION' ? 2 : \ 1/0) #map of each potential source of an event sourcemap(index) = ( index == 1 ? 'ROOM1_TEMPSENSOR' : \ index == 2 ? 'ROOM1_MOTIONSENSOR' : \ index == 3 ? 'ROOM2' : \ 1/0) #test room occupied window data ENTERTIME=0 EXITTIME=100 ENTERTIME_1=120 EXITTIME_1=150 #window #TODO: yticlabel #TODO: dynamic creation from datafile set object 1 rect from ENTERTIME,0 to EXITTIME,0.1 fc rgb 'black' set object 2 rect from ENTERTIME_1,0 to EXITTIME_1,0.1 fc rgb 'black' set xrange[ENTERTIME-10:EXITTIME+10] #TODO: set max to total index used set yrange[-1:10] set autoscale ymax #add some style set style line stylemap('TEMPMEASUREMENT') lt rgb "green" lw 3 pt 50 set style line stylemap('MOTION') lt rgb "blue" lw 3 pt 6 ps 2 #plot data. plot DATAFILE using 3:1:ytic(sourcemap($1)) index 0 with points notitle ls stylemap('TEMPMEASUREMENT'), \ DATAFILE using 3:1:ytic(sourcemap($1)) index 1 with points notitle ls stylemap('MOTION'), \ DATAFILE using 3:1:ytic(sourcemap($1)) index 2 with points notitle ls stylemap('TEMPMEASUREMENT') ###data file sample #WHO WHAT WHEN 1 TEMPMEASUREMENT 10 1 1 TEMPMEASUREMENT 20 1 1 TEMPMEASUREMENT 30 1 1 TEMPMEASUREMENT 40 1 1 TEMPMEASUREMENT 50 1 2 MOTION 15 2 MOTION 25 2 MOTION 35 2 MOTION 45 2 MOTION 55 3 TEMPMEASUREMENT 13 3 TEMPMEASUREMENT 23 3 TEMPMEASUREMENT 33 3 TEMPMEASUREMENT 43 3 TEMPMEASUREMENT 53 3 TEMPMEASUREMENT 63 The questions I have: 1) Is there a better way to do the time windows other then using objects? I really want to have all the data in data file. Is there a way to have the object pull the enter/exit time from the data file? I want to also add a label at the the ylabel for the windows. A yticmark if you will. How can I add one that isn't tied to a data point (more reason to want to pull windows from datafile. Just have some that y=0 that is labeled ROOM_OCCUPIED: __________ ________ _____ _____ ___________ 2) From what I have read online, I can't use a string for the y value. That is why I have the mapping functions to take the index (column one) and translate it to the name for the ytic. Is there a way to do this will out the map? 3) I want to get the "magic text" out of the plot call? I have tried everything but I can't seem to find a way to pass the string from the datafile into the stylemap call. I have tried stylemap($2),stylemap(stringcolumn(2)), and a few others. All fail. I know I can probably just take the strings out of the datafile and then just have two maps: source_index->source_name and style_index->name (for key). But I wanted to ask if there might be an easily or other way to do this. I'd love to not have those maps (source map mainly since I want it to be dynamic from datafile/ styles will not change that much) and be able to have all the strings in the datafile itself. That will let the data files be more human readable and have all the information to allow for a generic gnuplot script to generate ( use iterator to through all the datafiles instead of indexes within a single file). Any suggestions or comments would be great. I'm sure I have done things wrong/overly complex since I'm still new to gnuplot. Any coarse corrections would be great before I get in too much of a rabbit hole. Thanks. |