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.
Related
I have managed to plot two different data sets on the same axis however, I'm also looking to plotting another line showing their average.
The main problem is that both data sets have different X (time) values so it's not possible to add an average column at the end and plot that. (See the highlighted row 22 for example, corresponding Time values are different)
Is there any way I can plot an average of two plots on the same axis?
One idea that might work is to place the values of both series, one above the other in two new columns, sort this new data according to time, smooth it, then plot the smoothed combined data. Alternatively, you could do the smoothing by simply plotting the new sorted series, adding a moving average trendline to it, then change the formatting of the new series so that it is no longer visible (but the trendline is). Something like this:
In the above picture, series 3 is the plot of the sorted aggregate data of series 1 and 2. If you change the formatting of series 3 so that there is no line, you get something like this:
For my relatively small mock data sets, the results are admittedly poor (it was based on just 25 data points in each series), but if you have a large amount of closely spaced data, and you play around with the moving average window size, you might get something acceptable. If not, you should probably just interpolate both datasets to obtain two consistent time series.
I'd like to plot mean and standard deviation of multiple measures in one Gnuplot, if possible.
For example, object A and B has measures of lengths and weights like this (CSV format):
length,weight
100.0,0.1
100.5,0.12
98.8,0.09
100.1,0.11
Is it possible to plot this in a single figure with good visibility, i.e., the length is at the magnitude of 100, while the weight is at 0.1? I don't want the logarithmic way because in my real data, it doesn't make sense to logarithmize them.
Yerrorlines seems an option, but can histogram do this too?
Anyone knows how to do so in Gnuplot?
Thanks!
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 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.
My input to gnuplot looks something like this:
1:00am 1 10
1:00am 30 12
1:01am 60 18
1:01am 90 20
1:02am 120 21
...
The first column contains (what I'd like to be) the X-axis labels, while the second column contains the X-axis values. (In actual point of fact, I have one row per second, so many rows have '1:00am' as in the label column, then '1:01am', etc).
I can plot the values I care about using something like:
gnuplot> plot "my_data.txt" using 2:3 with lines
And I can set the X axis to have a tick (and label) every 30 minutes (which is 30 * 60 = 1800 seconds), but the label it uses is the X axis value (something like 3600 for one hour).
What I can't get is for the labels that show up under each tick to use the values from the first column. I can't even find anything that looks promising in the gnuplot manual. I've got to assume this is possible, I just don't know where to look.
Edit:
Progress, I've discovered the xticlabels() parameter to plot. The problem is that it seems to plot these labels for every xtic (that is, one per second in my data set), rather than at the intervals defined by set xtics.
Edit and Answer:
Turns out gnuplot has support for graphing time-series data. For the curious:
set timefmt "%H:%M:%S"
set xdata time
This causes the X axis data (once reformatted to match that pattern) to be interpreted as time-series data. This is then combined with
set xtics 3600
Formats the X axis as I described.
Sorry caught this late, but yes was to suggest set timefmt ... ; set xdata time. I always pass in my time format as %s but just as a common practice.