How to remove labels and arrows to the next plot in script - gnuplot

I have the following Gnuplot script:
set label "Threshold" at first 1.03, first -15
set arrow from graph 0,first -13 to graph 1, first -13 nohead lt 0 lw 5
plot [1:12][] pot_t(x) t "up" w lines ls 1
Plot this:
with a horizontal line at -13.
If I add a second plot in the script
plot [5:20][] pot_t(x) t "up" w lines ls 1
the horizontal line arrow and label still there.
How could I remove the label threshold and the dashed horizontal line?
Regards

labels and arrows stay in every subsequent plot until you explicitly remove them, like practically all gnuplot settings.
You can find out the identifier number of each of them with "show label" / "show arrow" and remove them via "unset".
set label 5 at 1,1 "Labeltext" # explicitly give the label an id
plot x # here's a label
unset label 5
plot x # and it's gone

Related

Set title for arrow in gnuplot

I've used the arrow to draw a vertical line and I would like to title it so it's shown in the key. Is there a way to do it? As far as I can tell for the manual, there's no title option in the syntaxis for arrow, but I'm sure there's a workaround.
The only thing I think of is drawing the arrow with the same color as something outside the plot range and use its title, but it's rather clumsy.
I'm using the terminal pngcairo, just in case it's relevant.
You can plot something with vectors, which will give a title in the key. It plots arrows based on data points. The using statement is x:y:Δx:Δy where the tail is positioned at (x, y) and the head is at (x+Δx, y+Δy). For a vertical line, you can turn off the arrow head and use Δx of zero:
set terminal pngcairo dashed
set output 'plot.png'
set angles degrees
set xrange [0:360]
set yrange [-2:2]
plot sin(x), '-' using 1:(-2):(0):(4) with vectors nohead lc rgb 'black' title '90 degrees'
90
e
Gnuplot will ignore anything with an invalid value (1/0 for instance). You can take advantage of this to plot what you want.
Suppose that we set a vertical line with
set arrow from 1,graph 0 to 1,graph 1 nohead lt 0
Now, if I want this to be in the key, I can just plot a line with lt 0 but specify the y-value as 1/0. This will insert it in the key, but will not actually draw the line.
plot [-3:3] x**2 t "X Squared", 1/0 t "Vertical Line" lt 0

Adding a typical error bar into the key not into the data points in Gnuplot?

I do not have error values for all my data. So instead of putting error bars into data points I want to add information about the mean error as a horizontal line (they are x axis errors, I do not have for y axis) into the corner of the plot like scales of maps.
Thanks!
You can add an arrow with bar heads which uses the same line style like your data points:
set style arrow 1 heads size char 0.5,90 lt 1
error_len = 1
set arrow from first 1,graph 0.95 rto first error_len,graph 0 arrowstyle 1
plot 'data.dat' lt 1
You must only tweak the arrow position and the error size.
You could use the stats command (since 4.6) to extract the x-values from your data to get an easier positioning of the error bar:
set style arrow 1 heads size char 0.5,90 lt 1
error_len = 1
stats 'data.dat'
set arrow from first 0.98*STATS_max_x,graph 0.95 rto first -error_len,graph 0 arrowstyle 1
plot 'data.dat' lt 1

How to plot horizontal lines from a single point

I have a dataset(a file) with a single column and some entries. I wish to plot a horizontal line for each entry, where each entry is the y-axis value of the line. How can I do this?
What a strange plot you're trying to make. You can do it using vectors without heads:
set style arrow 1 nohead
plot 'datafile' using (0.0):1:(0.0):(2.0) with vectors arrowstyle 1
Or, in gnuplot shorthand (just for fun):
p 'datafile' u (0.0):1:(0.0):(2.0) w vec as 1
adjust yrange and xrange accordingly

bring legend to the front in gnuplot

Is there a way to bring the key (legend) in gnuplot (epslatex terminal) to the very front? In my plot I experience that some filledcurves are on top of the small line samples of the key so that these are invisible. The lables in the key are placed on top as they are drawn by latex. I know that I could change the order in the plot (filledcurves first) but I actually want that the filledcurves hide the previously drawn lines in the plot itself.
Recent gnuplot versions allow you to say "set key opaque", which I think does what you want.
First plot your lines without the key plot x notitle ls 1, then plot your filledcurves, then plot yet the extra lines using the linestyles of the first lines, but so that they are out of the visible area:
set yrange [-10:10]
plot -x notitle ls 2, x**2/3-5 w filledc ls 5, x**2+100 t "first-line legend" ls 2
This gives you the legend at the top of the filledcurves, but the visible lines below. Hope this works with epslatex too.
#sfeam's answer is correct, as long as the key doesn't have overlap with the border. If it has, there's no way to bring the legend in front of the border, but you can bring the border to the back by "set border back".
So, a combination of "set key opaque" and "set border back" guarantees that the legend is on top of everything.
One can use dummy plot-elements with NaN (or keyentry for gnuplot 5.2.6). The key title will not be in front.
Here is a comparison between default, the NaN approach and key opaque.
reset session
set samp 10000
a = 10
set xrange [0:200]
set multiplot layout 2,2
set key title "default"
plot sin(x), cos(x)
set key title "NaNs dummy entries"
plot sin(x) t "", cos(x) t "",\
NaN t "sin(x)" ls 1, NaN t "cos(x)" ls 2
set key opaque title "key opaque"
plot sin(x), cos(x)
unset multiplot

setting multiple labels at the top of the x-axis

After the answer got in my earlier post drawing vertical lines in between bezier curves, I have been trying to label the segments separated by the dotted lines. I used x2label but found out that if I use it multiple times then the data gets replaced though they are positioned in different places. Below is the script:
set term x11 persist
set title "Animation curves"
set xlabel "Time (secs.)"
set ylabel "Parameter"
set x2label "Phoneme1" offset -35
set pointsize 2
set key off
set style line 2 lt 0 lc 1 lw 2
plot [0.04:0.15] "curve.dat" u 1:2 smooth csplines ls 1, "" u 1:($2-0.2):(0):(0.3) w vectors nohead ls 2, \
"curve.dat" u 1:2 with points
The output is the following.
I want to label Phoneme1, Phoneme2...and so on.. on top of each segment. How would I do it? Also as I was suggested in my earlier post to play with the line "" u 1:($2-0.2):(0):(0.3) w vectors nohead ls 2 to get a top to bottom vertical lines. But that also did not work. How do I get the lines from top margin to bottom? Thank you.
The horizontal lines
The horizontal lines can be accomplished with setting the yrange to an explicit value. Otherwise gnuplot would try to get some space between the lines and the axis. You could choose the values
set yrange [0.3:1.2]
Then you simply modify the vector using directions like so:
"" u 1:(0.3):(0):(1.2) w vectors nohead ls 2
(see below for the complete script)
The labeling of the sections
A quick way of doing this with your set of data would be this:
set key off
set style line 2 lt 0 lc 1 lw 2
set yrange [0.3:1.2]
plot [0.04:0.15] "Data.csv" u 1:2 smooth csplines ls 1, \
"" u 1:(0.3):(0):(1.2) w vectors nohead ls 2, \
"" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels
However, this will probably not look the way you want it to look. You could think of modifying your data file to also include some information about the labeling like:
#x-value y-value x-label y-label label
0.06 0.694821399177 0.65 0.1 Phoneme1
0.07 0.543022222222 0.75 0.1 Phoneme2
Then the labels line would simply look like:
"" u 3:4:5 w labels
The complete plot then looks like this:

Resources