I want to label the vertical line which is drawn in gnuplot using the set arrow command, at the top border. How can this be done? For e.g. I have drawn a vertical line at x=-3.8, in the attached image. I want to place the label at the top border at the point where this vertical line meets the top border of the plot..
Is it a best practice to label the vertical lines in this manner? I choose this way because in the plot near the point where the vertical line meets the x-axis, there is already a number. So I had no choice other than placing the label at the top border.
Please check the manual or in the gnuplot console type help label. You can set a label to certain coordinates with offset.
reset session
xPos = -3.8
set arrow 1 at xPos, graph 0 to xPos, graph 1 nohead lc "red" dt 4
set label 1 at xPos, graph 1 "myLabel" offset 0.5,-0.7
plot sin(x)
Related
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
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
I have a gnuplot script which plots a histogram. I used the following syntax:
set style data histogram
set style histogram cluster gap 2
set style fill solid
set logscale y
rgb(r,g,b) = int(r)*65536 + int(g)*256 + int(b)
plot 'histogram_data' using (column(0)):2:(0.5):(rgb($3,$4,$5)):xticlabels(1) w boxes notitle lc rgb variable
What the last line does is: using column 1 as x labels, column 2 as the height of the histogram bars, 0.5 as box width, and columns 3, 4 and 5 as the rgb values to colour the bars.
Now, the problem is that modifying the gap parameter in line 2 does not change in any way the spacing between bars, even though as far as I understand that is the correct way to adjust such spacing. I am using gnuplot 4.6 patchlevel 4.
I found a way to do this with boxes, though I do not consider it very clean:
plot 'histogram_data' u (column(0)*2+1):2 w boxes notitle lc rgb 'white',\
'histogram_data' u (column(0)*2):2:(rgb($3,$4,$5)):xticlabels(1) w boxes notitle lc rgb variable;
This command is plotting all the data of the main plot on even slots and a white box on odd slots. So the first line in the plot command is plotting the gaps between every box of the plot (the width of these gaps can be specified using the boxwidth property I think but I haven't tested this), while the second line is drawing the actual plot.
I could not find a way to do this with the histogram plotting style, keeping the variable colours specified in the data file.
I plot a data file containing 2 columns as a line. I also have data ranges for the x axis that I would like to use to color the background.
For example, in the data range from 41 to 70, I would like to color the background blue.
I know that these commands can color background but I haven't yet figured out how to use x values :
set obj 1 rectangle behind from graph 0, graph 0 to graph 1, graph 1
set obj 1 fillstyle solid 1.0 fillcolor rgb "blue"
Gnuplot supports multiple coordinate systems. As your already aware, there's graph where 0,0 is the lower left corner of the graph and 1,1 is the upper right corner of the graph. There's also screen. (0,0 is the lower left corner of the "screen"). The axes you're looking for is first. Note that you can even mix coordinate systems. the point first 50, graph 0 is at the bottom of the graph at the point 50 on the x axis. Putting this all together, you should be able to set your rectangle as:
set obj 1 rectangle behind from first 41, graph 0 to first 70, graph 1 back
set obj 1 fillstyle solid 1.0 fillcolor rgb "blue"
I also added "back" to the command so that the rectangle is drawn behind all the other plot elements
Can I get gnuplot to display the exact y-value or height of a data point (plotted using "with boxes") over its bar? I would like the plot to be easy to read so nobody has to line up the top of a bar with the y-axis and guess what the value is.
You can use the labels style and combine it into the plot command with the boxes style. The labels style expects 3 columns of data - the x coordinate, the y coordinate, and the actual label text.
For example, with the following data
1 4
2 6
3 2
4 8
the command (we set the yrange to 0 - 10 and boxwidth to 0.9 and set a solid fill style)
plot datafile u 1:2 with boxes, "" u 1:2:2 with labels offset char 0,1
produces
Normally, the labels would be centered on the specified point (the top edge of the box). By specifying an offset, we can move them up to just above the box. Here we used no offset in the x direction, but a unit of 1 in the y direction. We used the character coordinate system, so this corresponds to moving up by one character unit.
I can only think of putting the values where you want them "manually" like this:
set label "value" at 12,34
The numbers are coordinates according to your x and y ranges.
An automatic way would use "with labels", see e.g.
http://gnuplot.sourceforge.net/demo_4.4/stringvar.html