I have a data file consisting of 2 columns with a name and value in it.
foo 0.1
bar 0.2
fff 0.4
bbb 0.7
I want to plot this and annotate the text entry next to the data point.
I tried
plot 'file' using 1:2 with labels
but it didn't work. I guess the proble is that I have to rely on gnuplot using only the second column for y and equally spacing the x axis.
You can do something like
plot 'file' using 0:2 title 'title', \
'' using 0:2:1 with labels offset 0,char 1
This will first plot the data normally, then plot with labels on top, offset up by one character. The 0 column is a dummy column which gives an index to the data--0 for the first data point, 1 for the second, etc.
Another alternative would be to plot using a histogram.
Related
First-timer with gnuplot. Essentially I'm interested in what the subject says. I already have a mechanism that works in terms of rendering the bars and I just want to add label-values on the top of each bar:
I have the following data in a file called 'data.dat':
1,Json,457054
2,MessagePack,685440
3,Cbor,1273723
I employ the following gnuplot configuration file 'plot.gp':
##
# file_path - path to the file from which the data will be read
# graphic_file_name - the graphic file name to be saved
# y_label - the desired label for y axis
# y_range_min - minimum range for values in y axis
# y_range_max - maximum range for values in y axis
# column_1 - the first column to be used in plot command
# column_2 - the second column to be used in plot command
##
# graphic will be saved as 800x600 png image file
set terminal png
# allows grid lines to be drawn on the plot
set grid
# setting the graphic file name to be saved
set output graphic_file_name
# the graphic's main title
set title "Comparison"
# since the input file is a CSV file, we need to tell gnuplot that data fields are separated by comma
set datafile separator ","
# disable key box
set key off
# label for y axis
set ylabel y_label
# range for values in y axis
set yrange[y_range_min:y_range_max]
# to avoid displaying large numbers in exponential format
set format y "%.0f"
# vertical label for x values
set xtics rotate
# set boxplots
set style fill solid
set boxwidth 0.5
# plot graphic for each line of input file
plot for [i=0:*] file_path every ::i::i using column_1:column_2:xtic(2) with boxes
And I run the following gnuplot command:
gnuplot \
-e "file_path='data.dat' " \
-e "graphic_file_name='output.png' " \
-e "y_label='y' " \
-e "y_range_min='0000000'' " \
-e "y_range_max='1500000' " \
-e "column_1=1 " \
-e "column_2=3 " \
plot.gp
I can't figure out how to use 'with labels' at the bottom of the .gp file. Any help appreciated.
Here is yet another example. There is no need to do it in a for loop. You can use the pseudocolumn 0 (check help pseudocolumns) and lc var (check help linecolor variable) for setting the color.
Code:
### plot with boxes and labels
reset session
$Data <<EOD
1,Json,457054
2,MessagePack,685440
3,Cbor,1273723
EOD
set datafile separator comma
set style fill solid 0.3
set key noautotitle
set xrange[0.5:3.5]
set yrange[0:]
set format y "%.0f"
set grid x,y
set boxwidth 0.8 relative
plot $Data u 1:3:($0+1):xtic(2) w boxes lc var, \
'' u 1:3:3 w labels offset 0,0.7
### end of code
Result:
I'm developing a BIRT report and this is my situation.
I have one text element, let's say this:
blue square: 111
blue triangle: 222
red circle: 333
At the moment is static, and always displays the numbers you see. I would like to make the numbers dynamic so I created a SQL query and I have embedded it in a dataset. Let's say this is the output:
color shape count
blue square 123
red circle 456
blue triangle 789
I would like to set it up in such a way that each data set row matches the correct row in the text file, so it would become:
blue square: 123
blue triangle: 456
red circle: 789
And will be automatically updated.
I've binded the text element with the dataset and wrote this as a test:
blue square: <VALUE-OF>if (row["color"].toUpperCase() == "BLUE") { row["count"] }</VALUE-OF>
blue triangle: 222
red circle: 333
But when I run the report it doesn't work and the value is blank.
What am I doing wrong?
Thank you all for the help and let me know if you need more info.
You now have a dataset with row[color], row[shape], row[count] to simplify your desired output I would add a "computed column" to your dataset.
e.g. row[output] = row[color] + ' ' + row[shape] + ': ' row[count]
Once you added the computed column just drag and drop your dataset into your report (where you now have the text element) and delete the unused columns.
Tip: if don't know "computed columns":
use Google image search for "bird computed column example"
the Google text search might get you lost in birt forum lists.
Update:
It’s possible you have some typo in your scriptlet. In BIRT a scriptlet resolves to the last expression within itself.
Your scrptlet <VALUE-OF>if (foo) { bar }</VALUE-OF> doesn’t have a last expression. (It's not wrong but BIRT may not "understand" it this way) Try instead <VALUE-OF>var result = ''; if (foo) { result = bar }; result;</VALUE-OF> and format the scriptlet to several code lines with result; as last line. This is the same as if we consider the scriptlet as a function in some programming language and the last line of the function would be return result.
I'm doing a gif in gnuplot, and I have my data separated in blocks. I need the points to be white except from just the first row of every data block, which would be an orange point.
Currently my code is:
#...
do for [i=0:int(STATS_blocks-1)]{
plot "positions.txt" index i pt 7 ps 0.5 lc 'white' title "t = ".((i+1)*200)." Myr"
}
As you can see, this plots every data point white, including the first row.
Edited to show variable pointsize also
If I understand your data format correctly:
set linetype 11 lc "orange"
set linetype 12 lc "white"
set style data points
do for [i=0:N] {
plot "positions.txt" index i using 1:2:(column(0)>0 ? 0.5 : 2.0):(column(0)>0 ? 12 : 11) pt 7 ps variable lc variable
}
Variable color (if used) is always taken from the very last using column. Other variable properties work back from there.
I want to plot a vertical dotted red line in particular point (say 2.2) in xmgrace using script
You can either use an external tool such as pygrace or use grace's built-in batch capabilities. These have been touched upon here on SO before (see, for instance, here or here).
The following script plots a datafile (exp.dat) as empty circles, another data file (line.dat) as a red dotted line and sets the ranges, labels and major ticks of the two axes:
READ NXY "exp.dat"
READ NXY "line.dat"
WORLD XMIN 0
WORLD XMAX 5
WORLD YMIN 1
WORLD YMAX 5
xaxis label "My x label"
xaxis tick major 1
yaxis label "My y label"
yaxis tick major 1
s0 line type 0
s0 symbol 1
s0 symbol size 1.5
s1 linestyle 2
s1 color 2
To generate a vertical red dotted line that passes through 2.2 the contents ofline.dat should be something like
2.2 0
2.2 10000
You can generate such a file in a bash script with the following command:
echo "2.2 0\n2.2 10000" > line.dat
Save the script as mybatch.xmg and call it like this:
xmgrace -batch mybatch.xmg
If you want to directly generate an output you can add this directive:
PRINT TO "myplot.eps"
DEVICE "EPS" OP "level2"
PRINT
which will save your plot as myplot.eps (add -nosafe when calling xmgrace to get rid of the warnings).
I want to create a histogram of a file that contains :
1 144 12.54
2 564 02.34
3 231 01.23
4 452 07.12
and what I use for that purpose in my script is :
gnuplot << EOF
set terminal gif
set terminal postscript eps color enhanced
set output "diagramma";
set title 'Diagramma'
set key off
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9
set autoscale
set xlabel "May"
plot 'finalsumfile' using 1:2 with histogram, 'finalsumfile' using 1:3 with histogram
EOF
So I want the first column as x coordinate and the second and third columns as y.
BUT when I run my script occurs this error:
line 0: Too many columns in using specification
What am I doing wrong?
try:
plot 'finalsumfile' using 2:xticlabels(1) with histogram
Histograms typically only take 1 column of data, which the "x-value" being implicitly incremented by one each time starting from 0. To set explicit x labels, you need to use xticlabels which takes the string in the given column and uses that as the label.