I searched a while, but I didn't found the perfect solution for my problem.
So I'am here to ask you this:
I got a file with some measure values, date and time.
So I want to create a plotfile for gnuplot which automatically creates the plot diagram.
This is an example of the file which has to be plotted:
Date | Time | Temp1 | Temp 2 | Humidit
14.01.2015|20:08:32|23.0|22.12|37.0
14.01.2015|20:08:58|23.0|22.12|37.0
14.01.2015|20:09:25|23.0|22.12|36.0
14.01.2015|20:09:51|23.0|22.12|37.0
14.01.2015|20:10:17|23.0|22.12|37.0
14.01.2015|20:10:43|23.0|22.12|36.0
14.01.2015|20:11:09|23.0|22.12|36.0
So you see the time between each measure is very short.
Here is my gnuplot file:
set title "Title"
set output "Diagram.png"
set terminal png size 900,600
set ylabel "Temperature in °C"
set y2label "Humidity in %"
set xlabel "Days"
set autoscale xy
set grid
set xtics
set ytics
set y2tics 25
set y2range [0:100]
set grid
set datafile separator "|"
plot "test.txt" using 2:3 with lines title 'Temperature 1', \
"test.txt" using 2:4 with lines title 'Temperature 2', \
"test.txt" using 2:5 with lines title 'Humidity'
The result is a small vertical line from Humidity. Nothing else.
I don't get the right solution for me.
Does anyone have an idea, what I have to change in my plotfile?
Best regards
Julian
Related
I want to plot multiple files using a Gnuplot script.
However, I'm having some trouble to make it perfect.
My actual plots are something like that:
However, the linepoints plot is touching both the x-axis and the y-axis.
Therefore, I want to add extra space on xrange and yrange and get
which does not touch my axis.
I could to it manually using set xrange and set yrange.
However, I need to plot more than 100 different files, and it will be very time-consuming to do so.
There is some manner to automatically increase the size of xrange and yrange by some units?
My Gnuplot code is below.
#!/usr/bin/env gnuplot
set terminal epslatex size 7.5,3 standalone
set output 'pareto.tex'
set style fill solid 0.8
set ytics nomirror
set xtics nomirror
set grid lc rgb "#F2F2F2"
set xlabel 'Z_1'
set ylabel 'Z_2'
set xrange [170:215]
set yrange [7:40]
set style line 1 lt rgb "#000000" lw 12 pt 7 pointsize 3
plot "../exact.dat" using 1:2 title '$aug\,\epsilon$-CM' with linespoints ls 1
unset output
set output # finish the current output file
system('pdflatex --interaction=batchmode pareto.tex')
unset terminal
system
The command you are looking for is set offset. See the documentation for a full description.
Example:
set multiplot layout 3,1
# Default placement
plot 'silver.dat' with lines
# Additional whitespace combined with auto-extenstion to nearest ticmark
set offset 20,20,20,20
replot
# Additional whitespace with no auto-extension to nearest ticmark
set xrange [*:*] noextend; set yrange [*:*] noextend
replot
unset multiplot
I'm new to gnuplot and I have a problem:
I have 2 different text files, the first one (file1.txt) is something like this:
Switch,Port,BPS
S1,1,5464091.33
S1,3,5465677.33
S2,2,5463298.00
S2,3,5462729.67
S3,1,5461340.67
S3,3,5461772.33
and I plot "file1.txt" with an histogram:
plot avg_file using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader
this works fine.
Now I have file2.txt which contains a single value:
AVG_BPS
4844714.81
I would like to plot this value as a constant horizontal line over the previous graph (histogram).
This is my complete script:
# Terminal definition (PNG image)
set term png
# Settings
set datafile separator ","
set output 'myplot.png'
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 1
# Graph and Axis titles
set title "BPS"
set xlabel "Switch-Port"
set ylabel "bits-per-second"
# Plot
plot "file1.txt" using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader
Here is myplot.png:
Thanks
probably the best is to do a stats:
stats 'file2.txt' u 1
hor_value=STATS_min
and then add to your plot:
plot "file1.txt" using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader, hor_value
or alternatively put a line on top (before the last plot):
set arrow nohead from graph 0, hor_value to graph 1, hor_value front
I am trying to plot some data and I noticed that the y-axis tick values were all the same. I tried to add more precision using y format, but it did not work. I am unsure what I may have done wrong.
I initially thought that the plots were reflective of the data, but I discovered that the values were all the same. What was initially confusing was that the y-axis just shows the same repeating value on the major tics.
There is another similar question on StackOverflow (Repeating y-axis tick labels), but the solutions there did not work for me, and I would like to understand why gnuplot does this (which is also not explained in the other question).
%> gnuplot -V
gnuplot 4.4 patchlevel 3
set term png font 'Liberation Sans,10' size 800,200
set output "data/plotid09-" . timestamp . ".png"
set style line 1 lt 1 lw 1 lc rgb "purple" pt -1
set xlabel "Time" font 'Liberation Sans,10'
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set xtics font 'Liberation Sans,10'
set ytics font 'Liberation Sans,10'
set format y "%8.4f"
set ylabel "Kelvin"
plot "data.txt" using 1:6 ls 1 smooth bezier with lines title "Temperature"
I found the problem. Thanks for the comments and feedback.
Changing the line
plot "data.txt" using 1:6 ls 1 smooth bezier with lines title "Temperature"
to
plot "data.txt" using 1:6 ls 1 with lines title "Temperature"
fixed the issue. The problem was the "smooth bezier" option. I removed it and the problem went away, I saw a flat line and appropriate numbering on the major ticks as seen below. The plot below is an example of what one of the fields look like now (similar data, same issue).
#
I am new to gnuplot. I want to generate graph from data points with three components and standard deviation.
My data looks like this:
TYPE1 15 20 65 5
TYPE2 20 20 60 4
TYPE3 10 30 60 6
TYPE4 30 30 40 5
I want to plot a rowstacked bar for each TYPE with the 3 components stacked and an errobar at the top.
I wrote the following script to do this:
set terminal png
set output "sample.png"
set boxwidth 0.75 relative
set style fill pattern 0 border
set style histogram rowstacked
set style data histograms
set xtics 1000 nomirror
set ytics 100 nomirror
set noytics
set mxtics 2
set mytics 2
set ytics 100
set yrange [0:150]
set ylabel "Y"
set xlabel "X"
set title "Sample graph"
plot 'data.dat' using (100*column(2)/(column(2)+column(3)+column(4))) t "A" , '' using (100*column(3)/(column(2)+column(3)+column(4))) t "B" , '' using (100*column(4)/(column(2)+column(3)+column(4))):xtic(1) t "C"
This produced a graph which looks like this: .
But I am not able to get the errorbar on the top of each bar with deviation values in column 5. I tried different ways using rowstacked and errorbar styled bar graphs but had no luck.
For this you must know, that with the histogram style the boxes are placed at the x-positions 0, 1, etc. i.e. at the row number.
So for the errorbars you must use column(0) as x-coordinate:
set terminal pngcairo
set output "sample.png"
set boxwidth 0.75 relative
set style fill pattern 0 border
set style histogram rowstacked
set style data histograms
set yrange [0:150]
set macros
scale = '100/(column(2)+column(3)+column(4))'
set bars 2.0
plot 'data.dat' using ($2 * #scale):xtic(1) t "A" , \
'' using ($3 * #scale) t "B" , \
'' using ($4 * #scale) t "C",\
'' using 0:(100):5 with errorbars notitle lw 2 lt -1
The result with 4.6.3 is:
For convenience I used a macro scale. The macros work as follows: You define a string, like scale = '...' in the script above. That can be used later in any expression as #scale (you must have set macros enabled). The content of the scale string is then replaced before the respective command is executed.
if I add a xticlabel that uses 3 lines gnuplot cuts at the middle of the second line.
Is there any method to have xticlabels with several lines?
This is my data file:
"[17h30,19h00] 25" 1
"[03h30,10h00] 21" 1
"[03h00,12h00] 26" 2
"[18h00,19h30] 27" 3
"[20h30,22h00] 25" 4
"[13h00,14h30] 25" 4
"[19h30,21h30] 25" 5
"[14h30,16h00] 25" 5
"[16h30,18h00] 25" 5
"[09h30,15h00] 25" 9
And this is my gnuplot code:
set terminal postscript eps color
set output '| epstopdf --filter --outfile=hist.pdf'
set auto x
set yrange [0:10]
set style histogram clustered
set boxwidth 0.95 relative
set style fill transparent solid 0.5 noborder
plot 'hist.dat' using 2:xticlabels(1) with boxes lc rgb'blue90' notitle
Finally this is the graph produced:
Potential Problem 1: xtics overlap
You have a few options to help fix the xtic problem.
1) Rotate the xtics
set xtics rotate by -45
This will set the xtics to print at an angle from top-left to bottom-right.
2) Change the font size
set xtics font ",4"
You could make the font size tiny but unreadable.
3) add a gap between the bars of the graph
set style histogram gap 4
4) Change the data file
If you have control over the data file, you could try inserting some newlines into the xtic labels, e.g.
"17h30\n19h00\n25" 1
Potential Problem 2: xtics too long in general
I'm not quite sure from your question, but you may be running into this issue. Gnuplot has a built-in limit for the number of characters in a label, which is set to 50 in older versions of gnuplot and is 200 more recently. The post I linked to includes a workaround, which is to compile a version of gnuplot with an increased MAX_ID_LEN constant.
I had a similar issue, but in my case the labels where taken from two columns (a stringcolumn(1) and a numeric column(2)), while y-data in 3-rd column.
I split the labels in two using newline "\n"
using 2:3:xticlabels(stringcolumn(1) . "\n\n" . stringcolumn(2))
Basically inside xticlabels() you can give any string expression, for example
i also needed some numeric formatting for which i used instead of stringcolumn(2) the following expression:
gprintf('%1.0t*10^{%S}',column(2))
hope it helps