how to draw objects (rect) from a file - gnuplot

In gnuplot i can draw a rectangle via
set object rect from x0,y0 to x1,y1
How to read the coordinates x0,x1,y0,y1 from a file?

One way would be to put the line of code that sets the rectangle into a separate file and call that file from within the gnuplot script. So you have a file called "coord.txt" that contains the one line
set object rect from 2,2 to 4,40
and you have a gnuplot script called "rect.gp" that says
set title "call rectangle coordinates"
load "coord.txt"
plot x**2
If you now from within gnuplot type load "rect.gp" you get your graph with the rectangle.
That may not be exactly what you are looking for but maybe a first step.

You probably need to store the data from the file into variables, then use these variables to define the locations of objects. The way to do this is not straight as far as I know. Please refer to here. Good luck!

Related

How to connect two points with a curved line in GNUplot?

Its basically what the question says. I know that using tikz in latex it would be something like:
\draw[thick,dashed] (0,0) to [out=15,in=165] (1,0)
I would appreciate any help.
I think you have a misunderstanding how lines in gnuplot work. They are always directly connecting points. So you have to ways of faking it:
1) adding additional points and connecting them to "pretend" to have a curved line
2) define a function with the curve you want and plot it over the points (in xrange of point 1 to 2)
What I had to do is to great a .tex file with everything else a needed and then, in the .tex file I add the "\draw[thick,dashed] (0,0) to [out=15,in=165] (1,0)". But I wish I could know how to do it using GNUplot itself.

Set with lines in gnuplot

I can connect the dots of a data file by including with lines in the plot command. Is there a way to set this fixed (I was hoping for set with lines) so I don't have to explicitly include it in every call of plot?
Use
set style data line
to achieve this. Similar options are also available for functions
set style function boxes

gnuplot - multiple plot files using the same style settings, but different number of plot lines?

This is my problem: I have 4 different data files; and I need to create various plots on png, using data in these files.
I would like to have all in a function that I call in a script, so I would like to put together as many common statement as I can.
The plot have different file names, but they use mostly the same settings: the legend position, the title, the axis label, the range, border line style.
What change is the data, coming from different data files, the number of lines on the same plot (some has for example 1 set of data, others has 4-5 per plot), and the color to differentiate them.
Is there a clean way to group what is similar, so I don't end up writing the same things for each of my plot? I've check the doc and I was not able to find a solution to this; since the style is set for each dataset, so I can't really do anything to group it.
Found some questions here that look similar, but the problem is totally different...I don't need to merge data from different dataset, but I need to create different plot files, which only share most of the common settings. To make a generic example, I need a way to do something like a CSS style file, so the style stay the same, but the content of the plot (and the name of the file) changes.
I am using shell script for the code; so I wrapped a gnuplot command in a shell function.
Thanks
You can put all common settings in one file (lets say settings.gp) and load them from your main files with load 'settings.gp'. That works as if you would write the actual commands in place of the load command. Therefore you can define some variables before loading the settings file to change the behavior.
File settings.gp:
set terminal pngcairo
set output outfile
set style increment user
if (plotNum == 2) {
set style line 1 lt 5
set style line 2 lt 6
} else {
set for [i=1:5] style line i lt i+2
}
(Note, that this kind of if statement requires gnuplot version 4.6 and newer).
File main.gp
outfile = 'first.png'
plotNum = 2
load 'settings.gp'
plot x, x**2
The command set style increment user automatically iterates over line styles instead of line types in the plot command.
That is of course only an example, basically you can include any kind of tests and conditions in you settings.gp. An other possiblity is using the call command.

Gnuplot plane curve

I have a plane and a line in the XYZ coordinate system. The line is crossing the plane at some point through my view angle. So that the line is on one point of the diagram below the plane and at some other points above the plane. However in my current perspective the line is always visible although it is below the plane and should be therefore not visible. Does any command exist how to make this way of displaying possible?
Yes, you can use the hidden3d option for hiding the respective line parts behind the surface:
set ticslevel 0
set hidden3d
set view 40,50
set isosamples 30
splot x+y, "-" with lines
10 10 -10
0 0 10
e
This gives (with 4.6.4):
For this solution you need a data file (or the inline data as specified above), to define your line. Don't know, if another variant is possible.
Also, what I noted is, that the surface grid is drawn above the line. I haven't found a way to change that. I'll investigate on that, maybe its a bug.

titles next to lines in gnuplot

The feature list for the new version of gnuplot states that "plot title can be placed next to the plot line in the graph proper." This is something I would like to be able to do automatically, but I can't find mention of how to do this in the documentation (probably because it hasn't been written yet). Does anyone know how to do this?
I found the answer in the command line documentation, I assume the pdf hasn't been updated yet. Here's the text:
If you want the title of a plotted line to be placed immediately before or
after that line in the graph itself, use `at {beginning|end}`. This option
may be useful when plotting `with lines` but makes little sense for some
other plot styles.

Resources