I have some temperature data in a text file, and I would like to represent it in a 'boxed' plot, showing the temperature of each day like an histogram.
23 10 2012 12.3
28 10 2012 14.1
30 11 2012 30.4
...
I'm triying to represent it with a simiple gnuplot script like this:
set terminal png enhanced font font_file size size_x, size_y tiny
set xdata time
set timefmt "%d %m %Y"
set format x "%d"
set boxwidth 0.9 relative
plot u 1:4 w boxes
I would like to leave blank the days where no data is available, but gnuplot gives these days the value of the last day a data was available. For example, in the data file I wrote before, gnuplot would give a 12.3 to the 23th of october, but I would like leave this gap without any bar.
Is there a way to get this? I have discarted an histogram representation because I've read that it is not compatible with time data.
Thank you in advance
Your problem is the line set boxwidth 0.9 relative. Relative says that you're trying to fill 90% of the space between adjacent boxes. You probably want to set an absolute boxwidth. If you change your script to set boxwidth 0.9 absolute, then you'll see vertical lines. This is because when using time data, the x-axis unit is actually seconds, so your box is only ~1 second wide when your x-scale is multiple days. So, to get each box to be the width of a single day you would use
set boxwidth 3600*24
Here's the complete script:
set term png enhanced
set output 'foo.png'
set xdata time
set timefmt "%d %m %Y"
set format x "%d"
set boxwidth 3600*24
plot 'test.dat' u 1:4 w boxes
and the output:
Related
I am trying to use gnuplot from a csv file. There are quite a bit of similar posts but I haven't had any success from them. There should be 4 lines marked by the integer values and the times should make up the x axis.
data file: first column is H:M:S, rest are 0-100 values
00:26:45,34,12,3,7
00:27:14,31,10,5,9
00:27:43,27,7,2,4
00:28:18,32,11,4,6
00:28:45,36,17,6,7
00:29:35,39,16,1,3
00:30:48,24,12,5,4
00:31:33,32,9,2,8
00:32:15,27,12,3,7
00:32:45,34,15,6,4
gnuplot commands:
set datafile separator ","
set yrange [0:100]
set xrange ["00:00:00":"24:00:00"]
set xtics format '%H:%M:%S'
set timefmt '%H:%M:%S'
set xdata time
plot 'test.csv' using 1:2 with lines
So far all I get is a blank plot with 5 second increments starting at 00:00:00.
Any help would be greatly appreciated.
I was able to get the plot to show correctly by removing the xrange line. But the x-axis still doesnt display the exact times from the first column, Just every hour. Seems to just be a matter of more formatting.
I'm trying to plot a really long list, which represents frequency of some data. The x axis goes from 1 to 1881, and the y goes from 1 to 1978. I tried plotting with the following configurations:
set log y 5
set log x 32
set xtics 2
set ytics 5
plot "freq.dat" w boxes
But i get the following result:
Which is clearly not good because there are these intersections of the boxes. I want to have some kind of scale that have a lot more space between 10 and 150 than the outside of this area. How can i do that? I've tried every combination of logs and xtics and couldn't make it look good. The y axis seems good to me, the only problem is the spacing of x-axis.
Also, i want to know how to do this in gnuplot specifically (if possible).
Thanks.
It seems to me that your script overrides somewhere the default boxwidth. The default behavior is:
By default, adjacent boxes are extended in width until they touch
each other. A different default width may be specified using the set boxwidth command. Relative widths are interpreted as being a
fraction of this default width.
So for example this:
set terminal pngcairo enhanced
set output 'fig.png'
set log x 2
set log y 5
set yr [0.2:3125]
set xr [1:512]
set boxwidth 1 relative
set xtics 1,2,512 out nomirror
set ytics 1,5,3125 out nomirror
unset key
#set style fill pattern 6
plot 'freq.dat' w boxes lc rgb 'royalblue' lw 1.1
then yields:
I have the following csv file in which the columns represent hour,minute,view count respectively, exactly 1440 entries for every minute of the day. I would like to plot it using gnuplot. (Putting the HH:MM into one column is not possible due to the MySQL ONLY FULL GROUP BY.)
"0","0","71"
"0","1","55"
"0","2","56"
...
"23","57","66"
"23","58","70"
"23","59","75"
Currently I use the following commands:
set datafile separator ","
set timefmt "%H,%M"
set xdata time
set xtics format "%H:%M" time font "/:normal,8" rotate by 45 offset -1,-1
The time format is not rendered correctly, the hours are interpreted as minutes and the minutes are not shown at all.
I also tried set timefmt "\"%H\",\"%M\"" without success.
Two questions:
How can I parse the hour:minute and display it correctly?
If this data file had more columns and the timestamp was not in the first but in the n-th one, then how can I specify for gnuplot to render that, similar to using 0:n for plot?
Use this time format string
set timefmt "%H:%M"
Put this function somewhere:
catdate(x,y)=sprintf("%d:%d",x,y)
Then plot with:
plot 'data.dat' u (catdate($1,$2)):($3) w l
I have temperature data from eight different nonequidistant depths over several days and I would like to plot it as heatmap. As far as I know I have two options. I can use "with image" but that assumes equidistant points so that makes just 8 pixel thin strip or I can use pm3d which need proper grid(I am not sure what proper grid is). I found that dgrid3d can make the grid for me but that erases any dependency on depth for some reason. Can someone please explain this behavior to me?
Here is the code and the data I use.
https://docs.google.com/file/d/0B2TfUgjtGRVReV9ocFVvM1BKd2M
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
set view map
set dgrid3d
splot './Data/MO-03t_.txt' every ::2 u 1:3:4 with pm3d
the dgrid3d does not plot your data. Instead, something like two-dimensional splines are calculated from your data. Then, gnuplot creates a (by default) 10x10 matrix, and fills it with values interpolated from the splines. This matrix is then plotted.
But I have an other solution for you:
set timefmt "%Y-%m-%d %H:%M:%S"
set xdata time
# for the nice colors
set pm3d
# For debugging: place ticmarks only vor values with data
set ytics (0.02, 0.04, 0.06, 0.11, 0.31, 0.41, 0.61, 0.91)
plot './Data/MO-03t_.txt' every ::2 u 1:3:(1800):($3<0.2?.005:0.05):4 w boxxyerrorbars fs solid lc palette
The boxxerrorbars ... lc palette takes using <x>:<y>:<deltaX><deltaX>:<z>
The delta values are half the width of the boxes, i.e. it means plot a box from x-deltaX;y-deltaY to x+deltaX;y+deltaY for each datapoint.
Here, the width of the boxes is 3600 seconds, the height is either 0.1 or 0.01, depending on the y-value.
Here is the result:
However, you can still improve the height of the boxes.
And instead of 4+1 columns, you can also pass 6+1 columns with
using <x>:<y>:<xlow>:<ylow>:<xhigh>:<yhigh>:<z>
Here, the borders of the boxes are given as absolute values, not as distance from the x-y-value.
In GnuPlot:
How to set xtics to 1st of every month?
set xtics would not work for me the as the number of seconds per month varies.
set xmtics does not work for me because months are displayed without years and it is not shown to which year belongs a month.
It seems to me that gnuplot handles time surprisingly well. I assume your data in the following (or similar) format:
05/17/12 0.8188064359
05/18/12 0.97297057
05/21/12 0.9012782504
I used random numbers spread over year and a half to test this.
So first you need to tell gnuplot your x coordinate is time and what is the format it is written in:
set xdata time
set timefmt "%m/%d/%y"
From now on, gnuplot is expecting all ranges in the specified format, including the xtics and xrange commands. The only exception is the increment in xtics which should be in seconds.
set xrange ["05/01/12":"08/01/13"]
set xtics "01/01/12",2592000,"08/01/18"
Now you might argue, that the number of seconds in each month is different by a whole day (actually 2 days in February). However, gnuplot authors seem to think about this as well and they solved the problem to our liking. In other words, the above will ensure tics every 1st of a month. Here, I can only suggest to specify the printing format of the xtics
set format x "%d %b %Y"
which will result in "01 May 2012", etc.
After this, plot your data. Oh, when using time on x-axis, gnuplot requires using in the plot command, so even with a trivial data file as I had, I had to use
plot 'data.txt' using 1:2
I used gnuplot version 4.6 patchlevel 0 and output to postscript terminal.
If you will have different experience with your version or terminal, let me know in the comments.
set xtics will work ok if you set the number of seconds to the average number of seconds in a month.
I worked this out by assuming 365.2425 days in the average year, dividing by 12 to find the average days per month (approximately 30.4), multiplying by hours per day then seconds per hour, i.e:
365.2425 / 12 * 24 * 3600 = 2629746
Assuming your data was formatted as year-month and value, i.e:
2016-01 10000
2016-02 12000
2016-03 10500
Then you’d need commands such as:
set xdata time
set timefmt "%Y-%m"
set format x "%b/%y" # Or some other output format you prefer
set xtics "2016-01", 2629746, "2016-03"
plot "mydata.dat" using 1:2 with linespoints
If you want to set xtics in multiples of months then just add a multiplier in the set xtics line, e.g to get quarterly marks:
set xtics "2016-01", 3*2629746, "2016-12"
I found that if I assumed the number of days in a month to be 30 or 31 then some at some point in the chart, months would be missing their xtics.