i want to plot the contents of a database. It contains pairs of timestamp (e.g. 1298136675887128524) and power consumption of a node at that time (e.g. 159.562042). The power consumption is measured every 10th ms. It is a PSQL database. I am not really used to gnuplot so i ask before i spend a lot of time trying it the wrong way...
My idea would be to export the values i want to plot into a plain file like this:
1298136675887128524 159.562042
1298136675888238531 160.124031
1298136675890241275 158.321967
Then i would scale the timestamp so that it is represented on the x-axis in a user-readable way and try to plot everything. Since i am talking about >100000 of these lines i am not quite sure if this is the best way..
Thanks for the help!
There is no need to "scale" your xaxis. Just:
set xdata time
set timefmt "%s"
plot 'file' u 1:2
or something similar.
Use "every n" to skip n-1 points while plotting, if your plot is too dense.
Related
Good evening,
I have a problem with Gnuplot. I tried to sum up my problem to make the comprehension easier.
What I have : 2 sets of data, the first one is my experimental data, about 20 points, the second one is my numerical data, about 300 points. But the two sets don't have the same abscissa.
What I want to have : I want my numerical data be interpolate on the x-experimental abscissa.
I know it is possible to do that with Xmgrace (paragraph Interpolation at http://plasma-gate.weizmann.ac.il/Xmgr/doc/trans.html#interp) but with Gnuplot ?
What I want to have in addition : is it possible, then, to subtract the y-experimental data of my y-numerical data at the x-experimental abscissa points ?
Thank you in advance for your answer,
zackalucard
You cannot interpolate the ordinate values of one set to the abscissa values of the other. gnuplot has no mechanism for that.
You can however plot both datasets using one of the smoothing algorithms (check "help smooth") with common abscissa values (which might (be made to) coincide with the original values of one set.)
set table "data1.tmp"
plot dataf1 smooth cspline
set xrange [GPVAL_x_min:GPVAL_X_max] # fix xrange settings
set table "data2.tmp"
plot dataf2 smooth cspline
unset table
Now you have the interpolated data in two temporary files, and only need to combine them into one:
system("paste data1.tmp data2.tmp > correlation.dat") # unixoid "paste" command
plot "correlation.dat" using 2:4
(If you have a sensible fit function for both datasets, the whole thing becomes much easier : plot dataf1 using (fit1($1)):(fit2($1)))
You can use smoothing, this should do the trick
plot "DATA" smooth csplines
(csplines is just one options, there others, e.g. bezier)
But I don't think you can automatically determine the intersection of the smoothed curved. You use the mouse to determine the intersection visually, or alternatively fit some functions f(x) and g(x) to your curves and solve f(x)=g(x) analytically
I am plotting data that is recorded on the last day of the 3rd, 6th, 9th, and 12th months of the year. I would like the tic marks to be at 03/09, 06/09, ...
After reading the documentation, I thought this could be done by saying
set xtics "03/09", 7889220
because there are about 7889220 seconds in three months. But rather than starting with March, 2009, the tic marks start on the next day, shown here (with the remaining part of the plot removed):
Is there a way to force the tic marks to be at end of months?
UPDATED:
The date format in the input file is mm/dd/yyyy, which I am reading with these commands:
set xdata time
set timefmt "%m/%d/%Y"
and I'm then doing this:
set format x "%m/%y"
set xrange ["03/31/2009":"12/31/2010"]
Discussion:
The Gnuplot behaviour when you use set format x "%m/%y" will be to place xtics at month boundaries since that really is what this command is asking Gnuplot to do.
To solve your problem there may be two posisble approaches that you can take here depending on how large your data set is.
Approach1:
If you do have time stamps in your data file one possibility is to just use the xtics directly for plotting (suitable if you have a large dataset)
So you do away with all the time commands in your script and just use
plot 'Mydata.dat' u 2:xtic(1) w points
Approach2:
The other option is to set custom xtics, however you will have to do this by hand and if you have a large dataset this might be cumbersome (suitable if the dataset has tens of points)
set xtics ("03/09" "03/31/2009", "06/09" "06/30/2009", "09/09" "09/30/2009", "12/09" "12/31/2009")
Will give you tics at the exact days you need them to be.
Assumption:
I assume that the first column in your file are the time stamps and second column are the data values. Below, I show a graph where I use the manual setting approach (Approach 2).
Result with dummy data:
I have a file with 1200 rows. I am trying to use every command which will plot any chunk of data (for example from 6th to 800th data but every 5 points. I know how to exploit every to select first 1000 data (but not any chunk) and every 5 points separately. Is there any way to do that in an one liner?
Plot "file.dat" every ::::1000 every 5 u 1:4 fails to do that. Thanks!
See help every for an explanation of the empty sites in your every ::::1000 command:
Syntax:
plot 'file' every {<point_incr>}
{:{<block_incr>}
{:{<start_point>}
{:{<start_block>}
{:{<end_point>}
{:<end_block>}}}}}
In your case you need only the point parameters, block marks distinct parts of a data file which are separated by one newline.
So you plot command to select every 5th point between the 6th and 800th row is:
plot 'datafile.dat' every 5::6::800 using 1:4
If what you want is to plot every fifth point from only the first 1000 points, I do not think there is a (reasonably simple) way to do that in pure gnuplot. One option is to use an external command to do simple processing on your data file:
plot '< head -n 1000 datafile.dat' every 5
(For details on what that syntax does, type help plot special in gnuplot, or search for 'popen' in the gnuplot docs.)
I have data of this format:
2011-06-22 22:33:19 23 15
2011-06-23 09:46:13 12 79
2011-06-24 12:31:09 31 4
2011-06-24 17:34:10 7 2
2011-06-25 16:42:43 44 14
2011-06-25 20:26:52 54 9
2011-06-26 19:34:29 217 28
How can I create a histogram of daily activities with Gnuplot? By default, using these settings:
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set style data boxes
set grid
plot 'data' using 1:3 t "ins", \
'data' using 1:4 t 'dels'
the boxes will fit next to each other. But I would like to leave noneventful days at 0. Just like the Reputation graph here in StackOverflow behaves. If there's nothing on a given day, it should leave an empty place in the graph. If there's one event for one day, that box should be about the maximum width for one day. If there are more than one to given day, they all should be fit to that width.
Setting boxwidth is tricky because any value seem to give me 1-pixel wide "boxes".
Thanks kindly.
if I understand you correctly, then what you are trying to do is to my knowledge not possible with gnuplot. Or at least not in an easy way. And this is the reason why I think you'll have a hard time:
You cannot plot different box widths in a single plot. So trying to plot no box on an "non eventful" day and a single column on a day with one event will work just fine. Plotting multiple columns on one day where more than one event occurs in the same plot will fail because:
You cannot set different box sizes in the same plot
You need to offset the boxes on the same day according to the amount of events
There are ways to work around that problem for example plot two boxes of the same color next to each other to "simulate" a single box on one day and then make use of the smaller box width on days with two events. But this will very soon get pretty hairy and hard to maintain.
Maybe you want to think about using a different plot style? Take a look at histograms like here. Maybe one of the styles suites your data better. Or you could think about splitting your plot up into multiple plots?
I am a big fan of Gnuplot and I used it all along my studies for various projects.
Lately I wanted to use Gnuplot to chart some time series like weight loss, exercising results, gas consumptions etc.
Therefore I scale the x-axis like
set xdata time
set timefmt "%d.%m %Y"
set format x "%d.%m"
Now I want to use the fit-function to give me a linear fit. My problem is, that I cannot get that to work if the x-axis is time-related.
Then change the date to a number, for example a number of days starting from the first date, make the fit, and then convert the numbers back again into dates.
That way you'll have "regular" x and y data set.