0
votes

I have a simple dataset consisting of a date/time field (YYYY-MM-DD HH:MM) and a temperature field, taken at 1 minute intervals. I am trying to learn how to label points on a plot such than I can label the max and min temperatures.

The data is coming from an SQL server in a node.js app and the commands / data are being piped to gnuplot via STDIN with the output being a PNG. I can successfully plot the data, but now I am just trying to label the max and min temperature points on the plot, with the "coordinates" coming from an SQL query such that a min or max point would look like (x,y) = (2021-02-11 18:34, 72.57). Every command I try that should label points on the plot have no effect. And the examples that I find usually don't involve a date/time x-axis.

What is the magic ju-ju needed to be able to take an arbitrary data point and label it on the plot with a time/date x-axis? FWIW, since the data is being retrieved from an SQL server, I can format the data in whatever way makes it the easiest method needed to plot the data and more importantly, label the points that I want.

Thanks in advance for any advice!!

Justin

EDIT (per the first comment):

Here is what I am using in terms of gnuplot commands:

set term png size 1280,600
unset output
set datafile separator ","
set xdata time
set timefmt "%Y-%m-%d %H:%M"
set format x "%H:%M"
set ylabel "Temperature ˚F
set xlabel "Time
set style line 100 lt 1 lc rgb "grey" lw 0.5
set grid ls 100
set xtics border
set xtics rotate
set key off
$mydata << EOD
// this is where my code "prints" the SQL data to STDIN of gnuplot
// data is formatted: 2021-02-11 22:48,74.42
EOD
plot $mydata using 1:2 with lines

Note, I can format the data in whatever way that makes it easiest for gnuplot to process. I have found that sending YYYY-MM-DD HH:MM,TEMP has worked without issue.

I am tring to use the 'set label' command using a time/date as the x value and the temperature as the y value:

set label 1 'Maximum' at 2021-02-11 19:10,72.50

which does not produce any labels.

Here is an example plot where I want to label the max and min points:

Example Plot

1
Which commands have you tried so far to label your points? How do you plot your data so far? Which plotting style are you using? Please provide some minimal code, example data and ideally an example graph. See stackoverflow.com/help/minimal-reproducible-example - theozh

1 Answers

1
votes

When the x axis is time, the units are seconds. You are looking for the functions that convert between seconds (a floating point value) and a formatted time/date string.

strptime("timeformat",s) reads the time from the string s using the timeformat specifiers and converts it into seconds since the year 1970.

strftime("timeformat",t) produces a string by applying the timeformat specifiers to the time t given in seconds since the year 1970.

In the case you show, this would correspond to:

 myformat = "%Y-%m-%d %H:%M"
 set label 1 'Maximum' at strptime(myformat, "2021-02-11 19:10"), 72.50