I'm having a very difficult time getting "with lines" to work with gnuplot 4.6. I have a the following styles
set style line 2 lc 7 lt 1 pt 7 lw 1.5
set style line 3 lc 1 lt 1 lw 4.0
and I use the following plot command
plot '-' using 1:2 w lp ls 2 title 'test1','-' using 1:3 w lp ls 3 title 'test2'
NOTE lp in second plot
everything works fine, but I want to remove the data points from the second plot, so I've tried the following command
plot '-' using 1:2 w lp ls 2 title 'test1','-' using 1:3 w l ls 3 title 'test2'
NOTE l in second plot
but it fails to plot anything. The legend indicates that the style was picked up correctly, but there is no plot.
What am I doing wrong? Is there a way to use "linepoints" and shut off the points? I just want a line in the second plot.
I figured it out. I was passing one to many "\n" characters to pipe. It's interesting that it worked with both commands being "linepoints" but when one was changed to "lines" it did not work. Thanks for the input though.
Related
I am plotting several datafiles using the same linestyle (ls 1). However, I would like to differentiate the data using different pointtypes contained in wrd_pt on the code below.
The result is shown in the figure, where GNUPLOT plots as pointtype the values contained into the variable wrd_pt instead of the symbols (square, triangle, ...) associated with each numbers. I am using GNUPLOT 5.0 and there is no way I can update it (I am not the sudoer of the computer I am using) to use arrays for e.g. of the version 5.2.
Does anyone knows how I can fix that?
[... initializing ...]
wrd_pt ="5 7 9 11 13 15"
[... some other piece of code ...]
set output "plot_1a.eps"
plot for [i=1:words(fspo_one)] work_dir.word(fspo_one, i) u 1:5 w lp ls 1 pt word(wrd_pt, i) ps 1 notitle
unset output
Why not using plotting style with labels? Works also with gnuplot 5.0.
Something like this:
Code:
### point types as string from a string
reset session
wrd_pt = "5 7 9 11 13 15"
set xrange[0:10]
set style textbox opaque
set samples 10
plot for [i=1:words(wrd_pt)] '+' u 1:(i*$1**2) w l lw 2 notitle, \
for [i=1:words(wrd_pt)] '+' u 1:(i*$1**2):(word(wrd_pt,i)) w labels boxed notitle
### end of code
Result:
I am using gnuplot to postprocess some calculation that I have done and I am having hard time getting gnuplot to select the right lines as it is outputting some strange values that I do not know where come from.
The first 200 points of the results start in line 3 and stop in 202 but that is not working when I use every ::3::202.
Does anyone have any suggestions of what I am doing wrong?
Gnuplot image:
Datafile
set terminal pngcairo transparent nocrop enhanced size 3200,2400 font "arial,40"
set output "Mast41_voltage_muffe.png"
set key right
set samples 500, 500
set xzeroaxis ls 1 lt 8 lw 3
set style line 12 lc rgb '#808080' lt 0 lw 1
set style line 13 lt 0 lw 3
set grid back ls 12
set decimalsign '.'
set datafile separator whitespace
set ylabel "Spenna [pu]"
set xlabel "Timi [s]"
plot "mrunout_01.out" every ::3::202 using 2:3 title '5 ohm' with lines lw 3 linecolor rgb '#D0006E',\
"mrunout_01.out" every ::203::402 using 2:3 title '10 ohm' with lines lw 3 linecolor rgb '#015DD4',\
"mrunout_01.out" every ::403::602 using 2:3 title '15 ohm' with lines lw 3 linecolor rgb '#F80419',\
"mrunout_01.out" every ::603::802 using 2:3 title '20 ohm' with lines lw 3 linecolor rgb '#07826A'
unset output
unset zeroaxis
unset terminal
every refers to the actual plottable points. In your case, you have to skip 2 lines and the bunch of data at the end of your datafile.
Since you know the actual lines you need to plot I would pre-parse the file with some external tools like sed
So you can omit the every and your plot line becomes:
plot "< sed -n '3,202p' mrunout_01.out" using 2:3 title '5 ohm' with lp lw 3 linecolor rgb '#D0006E'
With yor datafile as it is, gnuplot has problems reading it. It can't even run stats on it:
stats 'mrunout_01.out'
bad data on line 1 of file mrunout_01.out
There is no need for using external tools, you can simply do it with gnuplot.
It's advantageous with your data that it is regular, every 200 points plotted in a different color.
And the data you want to plot is separated by one empty line from some additional data at the end of the file which you don't want to plot.
So, you simply address the 4th set of 200 lines in the 0th block via every ::600:0:799:0.
From help every:
Syntax:
plot 'file' every {<point_incr>}
{:{<block_incr>}
{:{<start_point>}
{:{<start_block>}
{:{<end_point>}
{:<end_block>}}}}}
Comments:
you can skip two lines at the beginning of the files with skip 2
you can plot your curves in a loop plot for [i=1:4] ...
you can define your color myColor(n) via index n from a string "#D0006E #015DD4 #F80419 #07826A"
you can define the legend myTitle(n) also from a list "5 10 15 20"
Script: (tested with gnuplot 5.0.0, version at the time of OP's question)
### plot parts of a file in a loop
reset session
FILE = "SO36103041.dat"
myColor(n) = word("#D0006E #015DD4 #F80419 #07826A",n)
myTitle(n) = word("5 10 15 20",n)
set xlabel "Timi [s]"
set ylabel "Spenna [pu]"
set yrange[0:30]
plot for [i=1:4] FILE u 2:3 skip 2 every ::((i-1)*200):0:(200*i-1):0 \
w l lw 3 lc rgb myColor(i) ti myTitle(i)
### end of script
Result:
I have a problem with gnuplot filled curves. I calculated some data to draw a picture using this code:
plot 'cont.dat' u 1:2 w filledcurves closed lc rgb "#ADFF2F" title "DF"
'cont2.dat' u 1:2 w filledcurve lc rgb "#CD5C5C" title "DA",\
'cont3.dat' u 1:2 w filledcurve lc rgb "#4682B4" title "(DF+DA)/2",\
'cont3.dat' u 1:2 w l lw 3 lc rgb "#4682B4" notitle ,\
'cont.dat' u 1:2 w l lw 3 lc rgb "#ADFF2F" notitle,\
'cont2.dat' u 1:2 w l lw 3 lc rgb "#CD5C5C" notitle
And everything was fine with this data:
But when I calculated another case. Trying to draw using the same code I received the following wrong result:
How could I change my code to fill the areas fully? I don't need this transparent 'holes'.
UPD:Here you can find data of green area which have been plotted wrong:
https://www.dropbox.com/s/xzheur2mx9h902f/cont.dat?dl=0
It doesn't matter either you plot three curves ore just one the result for each curve is the same.
I used GNUplot 4.6 for Windows
As mentioned in the comments, one of the problems in your data is that it is separated into blocks. But solving this issue is not enough. Let us focus in the figure below:
The figure on top corresponds to your original data. I plotted each data-block with different colors. If we remove the white spaces, the middle/blue figure is obtained, so the issue is not resolved yet.
If you look into the data, the first column of each data-block is sorted in the direction of the arrows (top figure), but the data-blocks are sorted in the opposite direction: They are disconnected!
So, the data-blocks should be sorted as 0-4-3-2-1 (or any cyclic order, such as 3-2-1-0-4). The white spaces should also be removed. Once you do this, the bottom/red figure is obtained.
This is part of the code I used to draw the picture:
plot for [i=0:4] 'cont_original.dat' u 1:2 every :::i::i w filledc t 'original block '.i,\
'cont_nospaces.dat' u 1:($2-0.2) w filledc t 'original without spaces',\
'cont_ordered.dat' u 1:($2-0.4) w filledc t 'ordered'
I have data for a CDF in a file which looks like the following:
0.033 0.0010718113612
0.034 0.0016077170418
0.038 0.0021436227224
... ...
... ...
0.847 0.999464094319
0.862 1.0
First column is the X-axis value and the second column is the CDF value on Y-axis. I set the line style as follows:
set style line 1 lc rgb 'blue' lt 1 lw 2 pt 7 ps 0.75 # --- blue
and subsequently plot the line with the following:
plot file1 using 1:2 title 'Test Line CDF' with linespoints ls 1
This all works fine, the problem seems to be that my CDF file is pretty big (about 250 rows) and Gnuplot would plot the marker/point (a circle in this case) for every data point. This results in a very "dense" line because of the over-concentration of markers such that the underlying line is almost not visible as I show in an example image below:
How can I selectively draw the markers so that instead of having them on all data points, I plot them after every 50 data points, without having to decrease the number of data points (which I believe is what "every n" in the plot command would do) in my data file or decrease the marker size?
There is no need to use two plots commands, just use the pointinterval option:
plot 'data' pointinterval 5 with linespoints
That plots every line segment, but only every fifth point symbol.
The big advantage is, that you can control the behaviour with set style line:
set style line 1 lc rgb 'blue' lt 1 lw 2 pt 7 ps 0.75 pi 5
plot 'data' w lp ls 1
You can plot the same function twice, once with lines only, and then with points every n points. This will draw less points without decreasing the amount of segments. I think this is what you want to achieve. For this example I have done set table "data" ; plot sin(x) to generate numerical sampling of the sin(x) function.
What you have at the moment is:
plot "data" with linespoints pt 7
which gives
Now you can do the following:
plot "data" with lines, "data" every 10 with points pt 7 lc 1
which gives what you want:
You can change the styling to meet your needs.
Although #Miguel beat me to it, but I'm also posting my solution below:
The idea is to once draw the line and then draw the points with the "every n" specifier. I changed my own Gnuplot script in the following manner. A kind of hack but works:
set style line 1 lc rgb 'blue' lt 1 lw 2 pt 7 ps 0 # --- blue
plot file1 using 1:2 title '' with linespoints ls 1, "" using 1:2 every 20 title 'Test Line CDF' with points ls 1 ps 0.75
This retains the nice curve, without quantizing it too coarsely while also keeping the points much better spaced.
With the following simple data file
1 1
2 3
3 4
and this script
set style line 2 lt 3 lc rgb "red" lw 3
show style line
set xrange [0:5]
set yrange [0:5]
plot "test_data.txt" u 1:2 ls 1
I don't see the line. Instead I only see the points. More than that, I don't see (1 1). Why? I followed the same steps form here
You have a data file, the example you reference uses functions. In gnuplot you need to specify that you want to use lines (with lines or in short w l) if you want to join data points with lines. Also, I can see (1 1) on your graph. Also I noticed you defined style line 2 but then used ls 1 instead of ls 2 to plot your data (that is you're not using the style you previously defined). Try
plot "test_data.txt" u 1:2 w l ls 2
If you also want to see the points together with lines, then use with linespoints or w lp:
plot "test_data.txt" u 1:2 w lp ls 2