The image below is an example that I need to reproduce and I do not know where to start.
Could someone advise me? I have a certain familiarity with gnuplot. How do I create multiple origins?
Without knowing your data structure it is difficult to make any suitable suggestions.
Since there seems to be no interest of the OP for an answer anymore, I will make a suggestion for others.
And since no data is given, I will assume something.
The example data contains several profiles separated by two empty columns.
Here the y-values (z-values in OP's graph) are in column 1 (range 0 to 2), and the x-values (x-values in OP's graph) are in column 2 (range 0 to 1).
You have a conditional offset and scaling.
So, then simply implement this for your x,y data using the ternary operator, check help ternary.
draw the rectangle and overwrite the ytic labels 1 -->0 and 3 --> 2
the pseudocolumn -2, i.e. the zero-based data(sub)block number (check pseudocolumns), is assigned to x0 which is used as x-offset.
if x0<=0 scale your y-values by 1 otherwise 1.5, and offset your values by 1 or 0, respectively.
Script:
### conditional offsets and scaling
reset session
# create some test data
set samples 50
set table $Data
f(x,a) = a*(-(x-1)**2+1) + (rand(0)*0.2-0.1)*x*(x-2)
do for [i=-3:15] {
plot [0:2] '+' u 1:(f($1,(i+4)/20.)) w table
plot '+' u ("") every ::0::2 w table
}
unset table
set obj 1 rect from first -3, first 0 to first 0, first 1 fc "black" fs pattern 7
yScale(x) = x<=0 ? 1 : 1.5
yOffset(x) = x<=0 ? 1 : 0
set xrange[-3:16]
set xtic 5 out add ("" -2) # remove xtic at -2
set mxtics 5
set yrange[0:3]
set ytic 1 out add ("" 0, "0" 1, "" 2, "2" 3) # overwrite y-tics
set mytic 2
set key noautotitle
set grid x,mx ls 1 lc "black"
plot $Data u (x0=column(-2)-3, $2+x0):($1*yScale(x0)+yOffset(x0)):-2 w l lc var
### end of script
Result:
Related
I am using feedgnuplot to create a barchart, in order to visually show how teams compare to each other (I'd use the term benchmarking, but that's not a suitable tag here).
What I would like to do is to colour one or more bars to indicate which team I'm working with.
Since pictures explain more, here is an example visually that I am attempting to reproduce:
Here we have several components: Firstly the horizontal line indicating the "group mean", and then four specific teams -- two of which are over-performing, and two of which are under.
Can you help with the red bars please?
Current attempt is produced with:
< ../gnuplot.csv /usr/bin/feedgnuplot --set 'style data histograms' --set 'style fill solid border lt -1' -xticlabels
The gnuplot command this generates is:
set grid
set boxwidth 1
histbin(x) = 1 * floor(0.5 + x/1)
set style data histograms
set style fill solid border lt -1
plot '-' using 3:xticlabels(2) notitle
2 "E" 8
3 "H" 7
4 "B" 6
5 "F" 5
6 "A" 4
7 "D" 3
8 "C" 2
e
From your example I don't see why you would need plotting style histogram. A simple bar chart with conditional color should be sufficient.
simply define a function based on your condition for bar coloring and use variable linecolor (check help lc variable).
if you want to plot the statistical mean value, use stats (check help stats).
the example below has just two columns column 1 text and column 2 numbers. Since you need an x-value for the bars, you take pseudocolumn 0, which is basically the row number with 0-based index (check help pseudocolumns).
Script:
### bar chart with conditional color
reset session
# create some random test data
set table $Data
set samples 26
y0 = 900
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
plot '+' u (alphabet[$0+1:$0+1]):(y0=y0-rand(0)*50) w table
unset table
myColor(col) = (_s=strcol(col), _s eq "C" || _s eq "J" || _s eq "T" || _s eq "X" ? \
0xff3333 : 0x3333ff)
set offset 1,1,0,0
set key noautotitle
set style fill solid 0.5
set yrange[0:1000]
stats $Data u 0:2 nooutput # get the mean value into variable STATS_mean_y
set label 1 at STATS_max_x, STATS_mean_y sprintf("mean=%.1f",STATS_mean_y) offset 0,0.7 right
plot $Data u 0:2:(myColor(1)):xtic(1) w boxes lc rgb var, \
STATS_mean_y w l lw 2 lc "web-green"
### end of script
Result:
I would like to remove specific xtic values (hours axis) in my graph that are not being used with other data. To be precise, I want to keep the following Xranges [0:5, 12:14], but not the xrange [6:11]. This is to help space out my data, since the unused space is currently smashing them together. I will attach a picture to visualize. Thank you for any help
I tried 'set xrange [0:5, 12:14]' but it did not work.
It is important to know the exact structure of the data because the plotting code needs to adapt to it.
For the following example the data structure is as follows:
7 blocks separated by double blank lines with x y z data.
Each block has a constant x value (from the values 0 1 2 3 5 12 14) whereas y and z vary.
If you have double blank lines you can address the blocks via index (check help index).
The x values are not equidistant, but you basically want to make them appear equidistant.
For this, you can use the pseudocolumn -2 (check help pseudocolumns) which contains the block number starting from 0.
The xtic label is used from column 1 (check help xticlabels).
Code:
### plot "non-equidistant" data equidistant
reset session
# create some test data
set print $Data
do for [x in "0 1 2 3 5 12 14"] {
do for [y=-40:40] {
print sprintf("%s %g %g", x, y, (16-x)*cos(0.05*y)**2)
}
print "\n\n"
}
set print
set xyplane at 0
set grid x,y
set view 60,140
set key at screen 0.3, screen 0.95 noautotitle
set xrange [-0.5:6.5]
splot for [i=0:6] $Data u -2:2:3:xtic(1) index i w l lc i
### end of code
Result:
I'm trying to get different points color and enter the points of second file on x-axis in the same graph.
I have two different files which contains : (y-axis:D,A,Q,F ; x-axis: 1-5 and 6-10)
1.file enter image description here
2. file enter image description here
Then I wrote this code to draw :
set style data labels
xcoord(N)= (N)
ycoord(N) = (column(0)+1)
symbol(N) = strcol(N) ne "/" ? strcol(N) : "/"
set xrange [0:10]
set yrange [0:5]
set ytics ("D" 1, "A" 2, "Q" 3, "F" 4)
plot for [N=0:6] 'doc.txt' using (xcoord(N)):(ycoord(N)):(symbol(N)):(symbol(N)) w labels tc lt 7 font "Helvetica,12" notitle, \
for [N=0:6] 'doc1.txt' using (xcoord(N)):(ycoord(N)):(symbol(N)):(symbol(N)) w labels tc lt 1 font "Helvetica,10" notitle
and currently the output looks like this:
graph of 1.file enter image description here graph of two data files enter image description here
As you can see, the all points are overlapping.
I want to use different colors for /, 5, g, 3 and o
and plot the points of second files in the x-axis 6-10.
How can I do that? Can someone help in correcting my commands.
Many thanks.
Not sure I understand the question fully, but to move the points from the second file over by six units on x you could modify the plot command to be:
plot for [N=0:6] 'doc.txt' using (xcoord(N)):(ycoord(N)):(symbol(N)):(symbol(N)) w labels tc lt 7 font "Helvetica,12" notitle, \
for [N=0:6] 'doc1.txt' using (6+xcoord(N)):(ycoord(N)):(symbol(N)):(symbol(N)) w labels tc lt 1 font "Helvetica,10" notitle
Can you clarify what color you want to use for the points? Your sample output does use a different color for the points in each file; is that not what you wanted?
Edit
I am making up a data format because you haven not shown any actual data, but perhaps the example below is enough to get you started.
$DATA << EOD
3 F / / 3 g 3
2 Q / / o / 5
1 A / o / / 5
0 D / / 5 / g
EOD
set xrange [0:7]
set yrange [-1:4]
set tics nomirror
set border 3
unset key
# These are the hexadecimal RGB representations of
# "red" "blue" "yellow" "green" "purple"
array colors = [0xFF0000, 0x0000FF, 0xFFFF00, 0x00FF00, 0xC080FF]
array symbol = ["/", "5", "g", "3", "o"]
color( sym ) = sum [i=1:5] (symbol[i] eq sym ? colors[i] : 0)
plot for [N=1:6] $DATA using (N) : (column(1)) : (strcol(N)) : (color(strcol(N))) \
with labels tc rgb variable font ":Bold"
Alternatively, you could do something with palette colors and numerical values rather than discrete RGB color names. That would be a different approach.
thank you very much for your answer. It's very very helpful.
[enter image description here][1]
[1]: https://i.stack.imgur.com/gLuoF.png
I can see now my graph, what I want to have.
Have a nice evening,! :)
Many thanks,
Chang.
I would like to draw a line with plots that contain "jumping" values.
Here is an example: when we have plots of sin(x) for several cycles and plot it, unrealistic line will appear that go across from right to left (as shown in following figure).
One idea to avoid this might be using with linespoints (link), but I want to draw it without revising the original data file.
Do we have simple and robust solution for this problem?
Assuming that you are plotting a function, that is, for each x value there exists one and only one corresponding y value, the easiest way to achieve what you want is to use the smooth unique option. This smoothing routine will make the data monotonic in x, then plot it. When several y values exist for the same x value, the average will be used.
Example:
Data file:
0.5 0.5
1.0 1.5
1.5 0.5
0.5 0.5
Plotting without smoothing:
set xrange [0:2]
set yrange [0:2]
plot "data" w l
With smoothing:
plot "data" smooth unique
Edit: points are lost if this solution is used, so I suggest to improve my answer.
Here can be applied "conditional plotting". Suppose we have a file like this:
1 2
2 5
3 3
1 2
2 5
3 3
i.e. there is a backline between 3rd and 4th point.
plot "tmp.dat" u 1:2
Find minimum x value:
stats "tmp.dat" u 1:2
prev=STATS_min_x
Or find first x value:
prev=system("awk 'FNR == 1 {print $1}' tmp.dat")
Plot the line if current x value is greater than previous, or don't plot if it's less:
plot "tmp.dat" u ($0==0? prev:($1>prev? $1:1/0), prev=$1):2 w l
OK, it's not impossible, but the following is a ghastly hack. I really advise you add an empty line in your dataset at the breaks.
$dat << EOD
1 1
2 2
3 3
1 5
2 6
3 7
1 8
2 9
3 10
EOD
plot for [i=0:3] $dat us \
($0==0?j=0:j=j,llx=lx,lx=$1,llx>lx?j=j+1:j=j,i==j?$1:NaN):2 w lp notit
This plots your dataset three times (acually four, there is a small error in there. I guess i have to initialise all variables), counts how often the abscissa values "jump", and only plots datapoints if this counter j is equal to the plot counter i.
Check the help on the serial evaluation operator "a, b" and the ternary operator "a?b:c"
If you have data in a repetitive x-range where the corresponding y-values do not change, then #Miguel's smooth unique solution is certainly the easiest.
In a more general case, what if the x-range is repetitive but y-values are changing, e.g. like a noisy sin(x)?
Then compare two consecutive x-values x0 and x1, if x0>x1 then you have a "jump" and make the linecolor fully transparent, i.e. invisible, e.g. 0xff123456 (scheme 0xaarrggbb, check help colorspec). The same "trick" can be used when you want to interrupt a dataline which has a certain forward "jump" (see https://stackoverflow.com/a/72535613/7295599).
Minimal solution:
plot x1=NaN $Data u 1:2:(x0=x1,x1=$1,x0>x1?0xff123456:0x0000ff) w l lc rgb var
Script:
### plot "folded" data without connecting lines
reset session
# create some test data
set table $Data
plot [0:2*pi] for [i=1:4] '+' u 1:(sin(x)+rand(0)*0.5) w table
unset table
set xrange[0:2*pi]
set key noautotitle
set multiplot layout 1,2
plot $Data u 1:2 w l lc "red" ti "data as is"
plot x1=NaN $Data u 1:2:(x0=x1,x1=$1,x0>x1?0xff123456:0x0000ff) \
w l lc rgb var ti "\n\n\"Jumps\" removed\nwithout changing\ninput data"
unset multiplot
### end of script
Result:
I have a data points file which contains
1 0 0
0 2 0
0 0 3
Then I wrote this code (snippet) to draw a variable size points for 1 or 2 or 3
xcoord(N) = (N)
ycoord(N) = (column(0)+1)
symbol(N) = strcol(N) eq "3" ? 3 : ( strcol(N) eq "2" ? 2 : (strcol(N) eq "1" ? 1 : 0) )
set xtics ("2000" 2, "2001" 3, "2002" 4)
set ytics ("M1" 1, "M2" 2, "M3" 3)
plot for [N=1:3] 'data.txt' using (xcoord(N)):(ycoord(N)):(symbol(N)*1) with points pt 7 ps var
Problem is all points have the same color. I want to use different colors for 1, 2 and 3. How can I do that?
Use linecolor variable to select a line type (or line style) based on a data column, see the two recent questions Gnuplot: Data blocks with different colours and Gnuplot with both color and xtic from data file
I'm not really sure, what the end result should be, but your example looks a bit strange. Why do you read the data as string and then convert it back to a number?
Just use
set offset 0.1,0.1,0.1,0.1
plot 'data.txt' matrix using 1:2:3:3 lc var ps var pt 7