Ive this script in gnuplot and I want to print multiple plots from 1 dataset. Ive tried this command but it seems that command needs another sama dataset to execute this command correctly. Do you know how to solve it?
plot '-' using 1:2, '=' using 1:3
1 1 5
2 2 5
3 3 5
e
With '-' you would have to enter the same data again. Check help special-filenames.
You better do:
$Data <<EOD
1 1 5
2 2 5
3 3 5
EOD
plot $Data u 1:2, '' u 1:3
Related
The data input from stdin fails for the second time as follows, how can I solve this problem?
plot '-' w l
0 0
5 0
e
replot '-' w l
^
unexpected or unrecognized token
replot after data input from stdin also fails
plot '-' w l
0 0
5 0
e
replot sin(x)
^
unexpected or unrecognized token
The following code works, so I don't know what's the problem.
plot sin(x)
replot '-' w l
0 0
5 0
e
I know plot '-' w l, '-' w l will draw multiple lines. But I'm using gnuplot from the program and I don't have all data to plot in advance. So I can't use this method.
I think I can solve this problem by writing the results of the process to a file, but can't I do that from stdin? I want to plot incrementally.
Thanks.
The recommended way to do this is by using a datablock rather than the pseudo-file '-'. Here is what the input stream to gnuplot should look like.
# Begin input
$DATA1 << EOD
1 2
3 4
EOD
plot $DATA1 with lines
$DATA2 << EOD
5 6
7 8
EOD
replot $DATA2
# or I would actually prefer
plot $DATA1 with lines, $DATA2 with lines
I am trying to plot a 'heatmap' and 'a cut of that heatmap' at a specific position using the data at the bottom. I would like to use use the every command in gnuplot to do so, but I fail. every ::13::17: is supposed to plot data from the line 13 to line 17. I am getting an error from gnuplot.
reset
set terminal pngcairo
set output 'stack.png'
set palette defined (0 "white", 1 "red")
unset key
set style fill solid
#----------------- 2D plot ---------------
plot 'stack.dat' using 1:2:(log10($3)) with boxes linecolor palette notitle
# ---- PLot a section of the 2D plot ----------
set output 'oups.png'
plot 'stack.dat' using 2:(log10($3)) every ::13::17: with lines notitle
'stack.dat' is the datafile name
1 1 0.081051938235759735
1 2 0.039051856845617294
1 3 0.017708625644445419
1 4 0.053782138973474503
1 5 0.069525197148323059
2 1 0.046054631471633911
2 2 0.005992549471557140
2 3 0.010819308459758759
2 4 0.001308800885453820
2 5 0.032604649662971497
3 1 0.078480839729309082
3 2 0.000435109512181953
3 3 0.073167815804481506
3 4 0.052882101386785507
3 5 0.016808584332466125
4 1 0.060769289731979370
4 2 0.028200428932905197
4 3 0.031424820423126221
4 4 0.052520859986543655
4 5 0.078694045543670654
5 1 0.029850590974092484
5 2 0.027807384729385376
5 3 0.036195535212755203
5 4 0.026242787018418312
5 5 0.048620097339153290
How can I make it works?
Is there a better way to plot sections of heatmap?
The short answer is to use
plot 'stack.dat' using 2:(log10($3)) every :::2::2 with lines notitle
When you have multiple blocks of records there is a distinction between lines in a datafile and records. So in order to specify a data sequence, you need the block and record indexes. Check the docs for more info (see Every): http://gnuplot.sourceforge.net/docs_5.2/Gnuplot_5.2.pdf
I have a data file like this:
1 1 2
2 2 3
3 4 nan
4 5 6
I want to plot it using:
plot "bla" u 1:2:3 w filledcurves, "" u 1:2 w lp, "" u 1:3 w lp
The problem is that the first part totally ignores the 3rd line, even though the nan is only in $3. Even though I have a value (4) in $2, it interpolates and skips it.
How do I make it not ignore that value?
I can make a workaround by replacing the nan by the value that should be there- (3+6)/2 in my case and then it will plot the 4 as well. There are two problems with that - I'll have to write a script that finds nans around the file, and it also plots a point when I'm using w lp as if there is a value there, but there isn't.
You're asking gnuplot's using to do something that it wasn't designed to do. Fortunately, there's a somewhat hacky solution. You need to use the 2-column version of filled curves which considers your data-points to make a closed loop. In this case, you want to plot the stuff from columns 1 and 2 and then the stuff from columns 3 and 1 (in reverse order). e.g.:
1 1
2 2
3 4
4 5
4 6
3 nan
2 3
1 2
If your datafile looks like this, you can plot it as:
plot 'datafile' u 1:2 w filledcurves
Now I'm pretty sure you don't actually want to re-generate your data-files, so the easiest thing is to use unix tools to do it for you:
plot "< sed 'x;1!H;$!d;x' test.dat | awk '{print $1,$3}' | cat test.dat -" u 1:2 w filledcurves
This should work. Note that the ugly sed command can be replaced by tac if you have that installed.
I've just read Gnuplotting data without a textfile, and I want to do the same thing, but with a "multi-plot". I currently have:
plot 'data.csv' using 1:3:2:6:5:7:xticlabels(8) with candlesticks title 'Quartiles' whiskerbars, \
'' using 1:4:4:4:4:4 with candlesticks lt -1 notitle
and I want to inline the data in data.csv.
This is easy enough:
set multiplot layout 1,2
plot '-' u 1:2
1 2
2 3
3 4
e
plot '-' u 1:2
2 3
3 4
4 5
e
Note that inline data is not really particularly happy with the '' pseudofile. You would actually need to include your entire data again at that point. So, If you want 2 traces on the same subplot of a multiplot:
set multiplot layout 1,2
plot '-' u 1:2, '-' u 1:3
1 2 3
4 5 6
7 8 9
e
1 2 3
4 5 6
7 8 9
e
plot '-' u 1:($2*$3)
1 2 3
4 5 6
7 8 9
e
This ends up being the same thing as if you had a datafile data.txt:
#data.txt
1 2 3
4 5 6
7 8 9
and plotted it with this (much simpler) script:
set multiplot layout 1,2
plot 'data.txt' u 1:2, '' u 1:3
plot '' u 1:($2*$3)
I want to use the plot command in gnuplot with expression evaluation, i.e.
plot "-" using ($1):($2) with lines
1 10
2 20
3 ?
4 40
5 50
e
But I want it to ignore the missing data "?" in such a way that it connects the line (and doesn't break it between 2 and 4).
I tried set datafile missing "?",
but in agreement with the online-help it does not connect the lines. The following would, but I cannot use expression evaluation:
plot "-" using 1:2 with lines
1 10
2 20
3 ?
4 40
5 50
e
Any ideas how to connect the lines and use expression evaluation?
Two column data
If you set up a data file Data.csv
1 10
2 20
3 ?
4 40
5 50
you can plot your data with connected lines using
plot '<grep -v "?" Data.csv' u ($1):($2) w lp
More than two column data
For more than two columns you can make use of awk.
With a data file Data.csv
1 10 1
2 20 2
3 ? 3
4 40 ?
5 50 5
you can run a script over the data file for each plot like so:
plot "<awk '{if($2 != \"?\") print}' Data.csv" u ($1):($2) w lp, \
"<awk '{if($3 != \"?\") print}' Data.csv" u ($1):($3) w lp
A reference on scripting in gnuplot can be found here. The awk user manual here.