Error plotting labels gnuplot - label

I would like to plot this datafile
"/root/temp.txt"
LB|30|421
CN|50|247
BR|20|370
SA|12|310
Where the first column is the X Axis, the second one is the Y Axis and the third one the label to put above each column of the histogram.
Before now, I use this syntax to plot the graph (but without any label)
set terminal png ;
set title "Hello" ;
set xlabel "Country" ;
set ylabel "values" ;
set style fill solid ;
set xtic rotate -45 ;
set datafile separator "|" ;
set style data histograms ;
plot '/root/temp.txt' using 2:xtic(1) notitle
But if I try to add labels gnu plot give me error!!
The syntax I use to add labels is
plot '/root/temp.txt' using 2:xtic(1):3 with labels notitle
Could you please help me?
Thank you

I am not sure that you can compress into one plotting format, but you can use replot (or replot-like plot):
plot '/root/temp.txt' using 2:xtic(1) notitle, '' u ($0):2:3 with labels notitle
Empty '' induce reuse the last input(file). Now, it equals with '/root/temp.txt'
To be nicer:
plot 'temp.txt' using 2:xtic(1) notitle, '' u ($0+0.1):($2+1):3 with labels notitle
Oh! And don't forget to set output of png term!

Related

Gnuplot: How to display actual values on top of each bar in a bar-plot?

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:

Change color of only one data point in gnuplot

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.

Gnuplot: label not displayed when plot with image

When I plot with image in gnuplot, the label that I set is not displayed. Everything else is correct. Here is my code:
#! /bin/sh
#
# Plotting the color map of correlation using the default Matlab palette
#
gnuplot <<EOF
reset
set terminal pngcairo size 700,524 enhanced font 'Verdana,10'
unset key
# border
set style line 11 lc rgb '#808080' lt 1
set border 3 front ls 11
set tics nomirror out scale 0.75
set xrange [0:20]
set yrange [0:20]
set xlabel 'Distance x/D_j [-]'
set ylabel '{/Symbol t} u_j/D_j [-]'
# disable colorbar tics
set cbtics scale 0
# matlab palette colors
set palette defined ( 0 "#000090",\
1 "#000fff",\
2 "#0090ff",\
3 "#0fffee",\
4 "#90ff70",\
5 "#ffee00",\
6 "#ff7000",\
7 "#ee0000",\
8 "#7f0000")
set output 'test.png'
set label 'aaa' at 2,17
plot 'Cuup_nf_a090_r050Dj_average' u 1:2:3 with image
EOF
What is strange is: if I plot the data file using a column which doesn't exist as the third data series, for example:
plot 'Cuup_nf_a090_r050Dj_average' u 1:2:4 with image
(I have only 3 columns in the file 'Cuup_nf_a090_r050Dj_average')
Sure, I get only blank (no data) in my image, but the label is displayed correctly.
So it seems that the label is covered by my data palette... I have tried to put 'set label' at the end of code, but it doesn't work either.
Does someone have an idea?
ps: my gnuplot version: Version 4.6 patchlevel 4
Thanks a lot in advance.
Labels have an option front|back to position them on the front or back layer. Default setting is back, so that labels not specifying an explicit layer are hidden when plotting with image:
$data <<EOD
1 2
3 4
EOD
set label 'default, hidden' at graph 0.6, graph 0.7 font ",20"
set label back 'back, hidden' at graph 0.6, graph 0.5 font ",20"
set label front 'front, visible' at graph 0.6, graph 0.3 font ",20"
plot $data matrix with image

Gnuplot - Labels cut off plot

My x and y labels are cut off the pic
I found the crop/nocrop option but didn't work.
How can I set a margin? and as you can see the titles (top right) are covered by the data. How can I set a margin there?
The following code comes from my bash script.
#set output
set terminal png large size 1920,1080 enhance background rgb '$BKGD_COLOR'
set output '$PLOT_OUTPUT_DIR/BW_${ArrayFile[$j]}_$DATE.png'
#set data
set datafile separator ","
set timefmt '%d/%m/%Y %H:%M:%S'
set xdata time
set format x "%d/%m/%Y\n%H:%M:%S"
#set axis (new style named 11, disable top and right axis, disable tics on top and right)
set style line 11 linecolor rgb '$TEXT_COLOR' linetype 1
set border 3 back linestyle 11
set tics nomirror font "/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf,16" textcolor rgb "$TEXT_COLOR"
#set grid
set style line 12 linecolor rgb '$TEXT_COLOR' linetype 0 linewidth 1
set grid back ls 12
#set line style
set style line 1 lc rgb '$RCVD_COLOR' pt 1 ps 1 lt 1 lw 2
set style line 2 lc rgb '$SENT_COLOR' pt 6 ps 1 lt 1 lw 2
#set text
set key font "/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf,10" textcolor rgb "$TEXT_COLOR"
set title 'Bandwidth (Mbps)' font "/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf,14" textcolor rgb '$TEXT_COLOR'
#Removed - set ylabel 'Mbps' textcolor rgb '$TEXT_COLOR'
set yrange [0:*]
#plot using the column 1 and 3 of the CSV file. with line points and title 'Bytes Received' and line style 1 (as defined above)
plot '$DIR/ResultsCSV/mg_bandwidth/${ArrayFile[$j]}.csv' u 1:3 w lp ls 1 t 'Bytes Received', '$DIR/ResultsCSV/mg_bandwidth/${ArrayFile[$j]}.csv' u 1:4 w lp ls 2 t 'Bytes Sent'
Set the font-size of your tics when setting the terminal. This size is used to determine the automatic margins:
set terminal png ... font ',16'
Alternatively you can set explicit margins with
set lmargin screen 0.05
set bmargin ...
For possible coordinate types, see e.g. https://stackoverflow.com/a/23180595/2604213
BTW: Use the pngcairo terminal which has a much better rendering quality.
#Christoph provided the answer about the margin, but you asked about your key as well.
In order to fix that, you can put the key in a different position. Doing
set key inside top left
will move the key to the left side, where the data won't cover it up. You can also move it ouside the plot altogether with
set key outside top right
which will move it to the right side and outside of the plot where it won't be covered up.
See help set key for more detail.

gnuplot label not displayed

I have lots of files to generate a plot for and therefore wrote a little script for gnuplot.
I want to add additional information with a label underneath the graph but my label is not displayed on the generated image.
Anyone gut an idea?
load.plt:
# template.gnuplot
set terminal png
filename = "results-05112012-".i.".dat"
plotfile = "results-05112012-".i.".png"
print filename." ".plotfile
set grid
set title "EER""
set output plotfile
set label "m = 20" at 0, 3 front tc rgb "#ffffff"
plot[0.35:0.75][0:100] filename using 1:6 title "FAR" w lp, filename using 1:7 title "FRR" w lp
unset output
unset label
i=i+1
if(i <= n) reread
I can see two reasons why the label might not appear. One is that the label is at the point (0,3) which is not within the plot region [0.35:0.75][0:100]. The other is that the label is white in color (#ffffff).

Resources