|
From: Norwid B. <nb...@ya...> - 2022-06-24 17:50:44
|
> > But how will one get infamation on the x-axis? > > It should start either at 2022-01-10 and then +7 days for > every xtick, or it can start with 148 also with +7 days > per step. > From this I bet your interest is the automated analysis of time series with gnuplot. Did you visit the gallery of examples on gnuplot.info, in particular about axis transformation?[1] Ben Hoey's example[2] is one both to easy to decipher and suitable as point of departure about how to interact from bash with gnuplot. (Your mileage may vary for other OSes like Windows or Mac.) For one, he stores the log data in a space separated file named `mydata.txt`: ``` 2019-02-01 15 2019-03-01 8 2019-04-01 16 2019-05-01 20 2019-06-01 14 ``` For two, the pattern to be applied is defined in a gnuplot script called to action from the CLI including arguments. It isn't like Python's argparse where you have to define and remember the flag's keys, but their counting and sequence: ARG0 refers to the name of the gnuplot script itself. ARG1, ARG2, etc. are for subsequent adjustments to affect gnuplot's work. Already modified for demonstration, Ben's script I store as `s1.spt` in the same folder as `mydata.txt` is the following (lines' length limit is 80 chars/line): ``` set xdata time # Indicate that x-axis values are time values set timefmt "%Y-%m-%d" # Indicate the pattern the time values will be in # set format x "%m-%y" # Set how the dates will be displayed on the plot # set xrange ["2019-01-01":"2019-12-31"] # Set x-axis range of values set yrange [0:30] # Set y-axis range of values set key off # Turn off graph legend set xtics rotate by -45 # Rotate dates on x-axis 45deg for cleaner display set title 'Squirrels Spotted' # Set graph title # set terminal jpeg # Set the output format to jpeg # set output 'output.jpg' # Set output file to output.jpg # introduced modifications, start: set xrange [ARG1:ARG2] # listen to arguments by the CLI set format x "%Y-%m" # coarse-to-fine time format on abscissa set grid set terminal pngcairo set output "test.png" # introduced modifications, end. plot 'mydata.txt' using 1:2 with linespoints linetype 6 linewidth 2 ``` Three, gnuplot is called from the CLI with `-c` (like /collect/ the arguments) in a pattern like ``` gnuplot -c s1.spt 2019-01-01 2019-12-31 gnuplot -c s1.spt 2019-03-14 2019-07-14 ``` with ARG1 defining the start, and ARG2 the end of the canvas. In the present example, the two have to be provided in the pattern YYYY-MM-DD. If the data contain more than two columns, either adjust `using` (short `u`) to indicate gnuplot the independent and dependent variable(s), or reorganize the log file submitted to gnuplot (e.g., AWK). On the other hand, it looks like the major bits and bolts now are at hand to automate your report generation. [1] http://gnuplot.sourceforge.net/demo_5.4/timedat.html [2] https://bhoey.com/blog/simple-time-series-graphs-with-gnuplot/ |