I'm trying to use gnuplot to view some profiling data; I have several files, each of the following format:
file_runXX.dat:
elapsed time, stage
elapsed time, stage
For example:
0 foo
1 step_1
1.5 step_2
2.3 step_3
and
0 bar
0.75 step_1
1.3 step_2
2.1 step_3
To plot them, I use:
set style data histogram
set style histogram columnstack
plot for [i=1:2] sprintf("%02d.log", i) using 1
And I get a graph with two vertical bars: at x=0 I have a bar going from y=0 to y=1, then y=1 to y=1.5 and y=1.5 to y=2.3. At x=1, I have the same data from the second file.
Two questions:
(a) Is this the proper way to do this (i.e., it works, but is there something better?), and
(b) How can I set the xlabels to read "foo" and "bar" (see column 2, row 1, of each file)? I've tried messing around with using 1:xtic(2) or title columnheader and a few other options, but it seems that's only usable if I have one file containing both timestamps (I'm not sure I can do this, since I sometimes have step 2a in one file but not in the other; yes, I'm aware that this can mean the colors are not going to be uniform between bars).
Thanks
or you could transpose the data:
#label step_1 step_2 step_3
foo 1 1.5 2.3
bar .75 1.3 2.1
... and then use following commands:
set style data histograms
set boxwidth .7
set style histogram rowstacked
plot for [COL=2:4] "all.dat" using COL:xticlabels(1)
this adds a legend which you can suppress or customize.
you could combine all data in one tab-separated file all.dat:
foo bar
1 .75
1.5 1.3
2.3 2.1
and then use following commands:
set style data histograms
set style histogram columnstacked
set boxwidth .7
plot for [COL=1:2] "all.dat" using COL title columnhead
Related
I have large files (~5 Gbs) whit constant increment on x-axis, let's say each dt.
I would like to know if I could set the every command of Gnuplot as logarithmic increment not linear.
plot "fileA.txt" u 1:2 every dt #linear increment of dt
This is because, if x-axis is in log-scale, then I want to have more points for low values of x in (10^-4,10^-2) but also not an oversampling in (10^4,10^2) range. Somehow a differential increment.
Does I have to use external programs like sed to re-write my file first?
A test plot is included as well as the data. In blue the full data, in red the ones with the every command. As you can see one loose the information for short x also oversample the plot for large x. the data file
Many thanks.
You could plot smoothed data with points:
set key left
set logscale x
set yrange [3.9:4.8]
set samples 30
set terminal png
set output "log.png"
plot "fort.11" title "raw" with points lc 3 pointtype 5 pointsize 2,\
"" title "smooth" smooth csplines with points lc 1 pointtype 5 pointsize 1
set samples 30 tells gnuplot to use 30 points equidistant in x
smooth csplines interpolates the datapoints
with points plots with points instead of lines, which would be the default
Note that this does not plot the original data, and that smooth csplines introduces new points if the original datapoints are too far apart. This might or might not be what you want.
I work with in-house benchmark tool. I use gnuplot (gnuplot 4.6 patchlevel 4) for visualization.
I need to represent results (method execution times for several runs) as stacked line chart, something like this:
Here is an excerpt from my .tsv data file:
Run MethodA MethodB MethodC
1 192 171 152
2 227 178 161
...
10 229 161 149
And the script I'm using:
#!/usr/bin/gnuplot -p
reset
clear
set terminal png size 640,480
set output "timings.png"
set key top left outside horizontal autotitle columnhead
set title "Third-party REST calls"
set xlabel "Run (ordinal)"
set xtics nomirror scale 0
set ylabel "Time (milliseconds)"
set ytics out nomirror
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75
plot "timings.tsv" using 2:xticlabels(1) , "" using 3, "" using 4
I get the following result:
Yes, it's not a line chart but histogram (I need to represent percentage of execution time of each method). I need slightly different result (the same histogram, not with boxes but with lines which connect boxes tops and with filling below lines), like this:
I'm aware of approach with filledcurve's (for instance, described there Creating a Filled Stack Graph in GNUPlot), but in that approach you need to sum values explicitly.
Is it possible to draw filled areas instead of boxes via gnuplot, e.g. convert histogram into stacked line chart?
You do need to sum values explicitly, but this is not a big issue. You can script it easily:
firstcol=2
cumulated(i)=((i>firstcol)?column(i)+cumulated(i-1):(i==firstcol)?column(i):1/0)
plot "file.dat" using 1:(cumulated(4)), "" using 1:(cumulated(3)), "" using 1:(cumulated(2))
I have a matrix of fft data over time, 8192 rows of data x 600 columns of time. The first column is a frequency label, the first row is shown below but doesn't actually exist in the data file, neither do the spaces, they are shown just for ease of reading.
Frequency, Sec1, Sec2, Sec3...Sec600
1e8, -95, -90, -92
1.1e8, -100, -101, -103
...
It is plotted in matlab with the following code (Apologies to other posters, I grabbed the wrong matlab code)
x is a matrix of 8192 rows by 600 columns, f is an array of frequency labels, FrameLength = 1, figN = 3
function [] = TimeFreq(x,f,FrameLength,figN)
[t,fftSize] = size(x);
t = (1:1:t) * FrameLength;
figure(figN);
mesh(f,t,x)
xlabel('Frequency, Hz')
ylabel('time, sec')
zlabel('Power, dBm')
title('Time-Freq Representation')
I cant quite figure out how to make it work in gnuplot. Here is a sample image of what it looks like in Matlab: http://imagebin.org/253633
To make this work in gnuplot, you'll want to take a look at the splot (for "surface plot") command. You can probably figure out quite a lot about it just by running the following commands in your terminal:
$ gnuplot
gnuplot> help splot
Specifically, you want to read the help page shown by running (after the above, when the prompt asks for a subtopic): datafile. That should tell you enough to get you started.
Also, the answers to this question might be helpful.
so here is the gnuplot command script that I ended up using. It has some additional elements in it that weren't in the original matlab plot but all the essentials are there.
set term png size 1900,1080
set datafile separator ","
set pm3d
# reverse our records so that time moves away from our perspective of the chart
set xrange[*:*] reverse
# hide parts of the chart that would make the 3d view look funny
set hidden3d
# slightly roate our perspective and compress the z axis
set view 45,75,,0.85
set palette defined (-120 "yellow", -70 "red", -30 "blue")
set grid x y z
set xlabel "time (secs)"
set ylabel "frequency"
set zlabel "dBm"
# plot all the data
set output waterfall.png
splot 'waterfall.csv' nonuniform matrix using 1:2:3 with pm3d lc palette
I have an experiment where I measured the performance of some algorithms relative to three baselines. I'd therefore like to plot histograms for the algorithms, with horizontal lines of various styles drawn through the histogram bars to show the baselines.
Below is an example which I produced by manually drawing horizontal lines on a graph produced by Gnuplot. The histograms "sentence" and "document" represent the algorithms I tested, and "mono", "random", and "MFS" are the baselines.
Is there some way I can do this within Gnuplot itself? If not, can anyone recommend another tool which can do this? Or perhaps there's a better visualization technique I should be using instead?
This is definitely possible. Here's a little example that I cooked up:
First, the datafile "data.dat":
#histograms
1 3 stack1
2 2 stack2
3 1 stack3
#mono
.6
.6
1.5
1.5
3.1
3.1
Now the gnuplot script to plot it:
set yrange [0:*]
set style data histograms
set style histogram cluster gap 1
IDX=-1
xpos(x)=(IDX=IDX+1, IDX%2==0)?(IDX/2-.5):(IDX/2+.5)
set style fill solid
plot 'data.dat' index "histograms" u 1:xtic(3) title "column1", \
'' index "histograms" u 2 title "column2", \
'' index "mono" u (xpos($1)):1 w lines ls -1 title "mono"
This is a little more tricky than my last version. When plotting a cluster of histograms, each cluster is centered on an integer starting at 0 and incrementing by 1 for each cluster (regardless of your setting for xtics and labels). What I've done is used that information to simplify the datafile. Now this plot command plots 2 different data sets as histograms (taken from each column in the "histogram" portion of the datafile), the first one adds the xtic labels. Then the tricky part: I write a function which has side-effects (gnuplot inline-functions are new in gnuplot 4.4 I think). Each time it is called, the value for the variable IDX is incremented -- So, the current position on the xrange is always IDX/2. This function alternates between returning IDX/2-.5 and IDX/2+.5. Note that to create another dataset random, you'll need another function xpos2 which is the same as xpos1 except it uses a separate iterator.
I have a line chart. The line represents the average thickness of material we apply to glass. The Y Axis represents the thickness and the X axis represents time. Say the range of values on the Y axis is between 1 and 10. The average thickness is say typically between 3 and 5, but must fall within a range, on the low side of 2 and on the high side of 7. I would like to shade the area of the graph between 2 and 7, to indicate the acceptable range of values. Can this be done?
Add a second value series, and change it to the "Range" chart type. This will allow you to set the high / low Y values discretely. Rather than choosing a field for these values, just edit the expression and set the static values (in your case, 2 and 7).
From there, edit the series "fill" properties - select Pattern, and find one that works for ya. There a good set of % fills (5 percent, 10 percent, etc.) midway down the list.
Hope this helps.