I am trying plot data sets consisting of 3 coordinates:
X-coordinate, x-coordinate and the number of occurrences.
example:
1 2 10
3 1 2
3 2 1
I would like to draw for every line a dot at x,y with a diameter which is depending on the third value.
Is that possible with Gnuplot?
Create a 2D plot with variable point size. See the demo.
Example:
plot 'dataFile.dat' u 1:2:3 w points lt 1 pt 10 ps variable
This is basically equivalent to the existing answer, just shorter:
plot 'dataFile.dat' with circles
Credit: Gnuplot: plot with circles of a defined radius
Related
I have a file "a_test.dat" with two data blocks that I can select via the corresponding index.
# first
x1 y1
3 1
6 2
9 8
# second
x2 y2
4 5
8 2
2 7
Now I want to connect the data points of both indices with an arrow.
set arrow from (x1,y1) to (x2,y2).
I can plot both blocks with one plot statement. But I cannot get the points to set the arrows.
plot "a_test.dat" index "first" u 1:2, "" index "second" u 1:2
From version 5.2 you can use gnuplot arrays:
stats "a_test.dat" nooutput
array xx[STATS_records]
array yy[STATS_records]
# save all data into two arrays
i = 1
fnset(x,y) = (xx[i]=x, yy[i]=y, i=i+1)
# parse data ignoring output
set table $dummy
plot "" using (fnset($1,$2)) with table
unset table
# x2,y2 data starts at midpoint in array
numi = int((i-1)/2)
plot for [i=1:numi] $dummy using (xx[i]):(yy[i]):(xx[numi+i]-xx[i]):(yy[numi+i]-yy[i]) with vectors
Use stats to count the number of lines in the file, so that the array can
be large enough. Create an array xx and another yy to hold the data.
Use plot ... with table to read the file again, calling your function
fnset() for each data line with the x and y column values. The function
saves them at the current index i, which it increments. It was
initialised to 1.
For 3+3 data lines, i ends up at 7, so we set numi to (i-1)/2 i.e. 3.
Use plot for ... vectors to draw the arrows. Each arrow needs 4 data
items from the array. Note that the second x,y must be a relative delta,
not an absolute position.
I have a survey data baseline and endline. I am trying to plot bar plot for qualification of the respondent in each group (baseline/endline).
I am using the following code:
graph bar, over(qualification) over(time)
It is giving me different output from what I want.
I want the bars for endline and baseline for each category to be present parallel.
I am also attaching a reference picture to get the better idea about what I want.
The order of the over options of graph bar matters.
Consider this example:
clear
input x str1 a b
1 "a" 1
2 "a" 2
3 "b" 1
4 "b" 2
end
graph bar x, over(a) over(b) title("over(a) over(b)")
graph bar x, over(b) over(a) title("over(b) over(a)")
It looks like you need to swap the order of your over options.
I am looking for a command line that allows to draw a square in my plot in GrADS. Here is an example
I would like to get a command line which allows me to draw a square like the one that I show on my picture example.
I assume the boundaries of the square you want to draw are based on lat/lon coordinates, and the bottom left corner is at (4N, 74W) and the upper right corner is at (8N, 72W). The following script fragment should work, but you must draw the plot first in order to set up the scaling between world coordinates and X,Y location on the page.
'q w2xy -74 4'
xpos1=subwrd(result,3)
ypos1=subwrd(result,6)
'q w2xy -72 8'
xpos2=subwrd(result,3)
ypos2=subwrd(result,6)
'set line 2 1 6' '* a thick, red line
'draw rec 'xpos1' 'ypos1' 'xpos2' 'ypos2
This is what it looks like if you are working with GrADS interactively:
ga-> q w2xy -74 4
X = 4.77083 Y = 3.08333
ga-> q w2xy -72 8
X = 5.74306 Y = 5.41667
ga-> set line 2 1 6
SET LINE values: color = 2 style = 1 thickness = 6
ga-> draw rec 4.77083 3.08333 5.74306 5.41667
I'm using the following gnuplot commands to create a plot:
#!/bin/bash
gnuplot << 'EOF'
set term postscript portrait color enhanced
set output 'out.ps'
plot 'data_file' u 3:2 w points , '' u 3:2:($4!=-3.60 ? $1:'aaa') w labels
EOF
where data_file looks like this:
O4 -1.20 -0.33 -5.20
O9.5 -1.10 -0.30 -3.60
B0 -1.08 -0.30 -3.25
B0.5 -1.00 -0.28 -2.60
B1.5 -0.90 -0.25 -2.10
B2.5 -0.80 -0.22 -1.50
B3 -0.69 -0.20 -1.10
I want gnuplot to label all points with the strings found in column 1, except the one where column 4 is equal to -3.60 in which case I want the aaa string. What I'm getting is that the $4=-3.60 data point is being labeled correctly as aaa, but the rest are not being labeled at all.
Update: gnuplot has no problem showing numbers as labels using the conditional statement, ie: any column but 1 is correctly displayed as a label for each point respecting the conditions imposed. That is, this line displays column 2 (numbres) as point labels respecting the conditional statement:
plot 'data_file' u 3:2 w points , '' u 3:2:($4!=-3.60 ? $2:'aaa') w labels
Update 2: It also has no problem in plotting column 1 as point labels if I plot it as a whole, ie not using a conditional statement. That is, this line plots correctly all the point labels in column 1 (strings):
plot 'data_file' u 3:2 w points , '' u 3:2:1 w labels
So clearly the problem is in using the conditional statement together with the strings column. Any of these used separately works just fine.
In a more clean way maybe, this should work. It seems label can't display a computed number if it isn't turned in a string.
#!/bin/bash
gnuplot << 'EOF'
set term postscript portrait color enhanced
set output 'out.ps'
plot 'data_file' u 3:2 w points , '' u 3:2:($4!=-3.60 ? sprintf("%d",$1):'aaa') w labels
EOF
Is this what you want?
#!/bin/bash
gnuplot << 'EOF'
set term postscript portrait color enhanced
set output 'out.ps'
plot 'data_file' u 3:2 w points , \
'' u (($4 == -3.60)? 1/0 : $3):2:1 w labels
EOF
All I do here is set (x) points where the column 4 equals -3.6 to NaN (1/0). Since gnuplot ignores those points, life is good. I think the problem with your script is that you were filtering a column where gnuplot expects string input -- although I haven't played around with it enough to verify that. I just switched the filter to a column where gnuplot expects numbers (the x position) and it works just fine.
I can easily calculate the values for sinc(x) curve used in Lanczos, and I have read the previous explanations about Lanczos resize, but being new to this area I do not understand how to actually apply them.
To resample with lanczos imagine you
overlay the output and input over
eachother, with points signifying
where the pixel locations are. For
each output pixel location you take a
box +- 3 output pixels from that
point. For every input pixel that lies
in that box, calculate the value of
the lanczos function at that location
with the distance from the output
location in output pixel coordinates
as the parameter. You then need to
normalize the calculated values by
scaling them so that they add up to 1.
After that multiply each input pixel
value with the corresponding scaling
value and add the results together to
get the value of the output pixel.
For example, what does "overlay the input and output" actually mean in programming terms?
In the equation given
lanczos(x) = {
0 if abs(x) > 3,
1 if x == 0,
else sin(x*pi)/x
}
what is x?
As a simple example, suppose I have an input image with 14 values (i.e. in addresses In0-In13):
20 25 30 35 40 45 50 45 40 35 30 25 20 15
and I want to scale this up by 2, i.e. to an image with 28 values (i.e. in addresses Out0-Out27).
Clearly, the value in address Out13 is going to be similar to the value in address In7, but which values do I actually multiply to calculate the correct value for Out13?
What is x in the algorithm?
If the values in your input data is at t coordinates [0 1 2 3 ...], then your output (which is scaled up by 2) has t coordinates at [0 .5 1 1.5 2 2.5 3 ...]. So to get the first output value, you center your filter at 0 and multiply by all of the input values. Then to get the second output, you center your filter at 1/2 and multiply by all of the input values. Etc ...