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.
Related
I have
Row1 = "set tmargin screen 0.92; set bmargin screen 0.40" # Top and bottom margins
Row2 = "set tmargin screen 0.40; set bmargin screen 0.20"
Col1 = "set lmargin screen 0.07; set rmargin screen 0.50" # Left and right margins
Col2 = "set lmargin screen 0.50; set rmargin screen 0.87"
set label "LABEL" at 0.4,0.2
What does 0.4,0.2 mean? It is not coordinates of the first graph, it is not in the same units like margins?
Please check help label and help coordinates.
Form gnuplot help:
The commands set arrow, set key, set label and set object allow you to
draw something at an arbitrary position on the graph. This position is
specified by the syntax:
{<system>} <x>, {<system>} <y> {,{<system>} <z>}
Each can either be first, second, polar, graph, screen, or
character.
...
If the coordinate system for x is not specified, first is used. If
the system for y is not specified, the one used for x is adopted.
So, in your case it means the label is placed at coordinates 0.4 of x1-axis and 0.2 of y1-axis.
Hi to whole stackoverflow group,
I am having a series of problems when defining the axes range in my graphic
and format in general, and I would like to share it with you to see if among all we can find the error
I have found on this website a user who has made it similar. My idea is to have something similar like the graphic of the link below. But for some reason, it's probably silly, it does not appear correctly.
My code is as following:
set term post eps enhanced color "Times-Roman" 14
set output "ComparacionPurezaMetodos.eps"
set key off
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.8
set xtic rotate by 90 scale 0
unset ytics
set y2tics rotate by 90
set y2label 'Ti_3SiC_2 content, wt{/Symbol\045}' offset -2.5
#set xlabel ' '
set size 0.6, 1
set label 'Powder mixture' at graph 0.5, -0.1 centre rotate by 180
plot 'datos.txt' using 1:(-1):3 with labels rotate right, 'datos.txt' using 1:2 with boxes
and the data are very simple:
# index, purity, name
1 98 Ti/Si/TiC
2 94 Ti/TiSi_2/TiC
3 93.6 Ti/Si/C
4 92 Ti/SiC/TiC
5 93 Ti/SiC/C
6 98 Ti/Si/C + Al
and I expect an output image like figure 4 (pag 6) of chapter 1 of this link:
https://books.google.es/books?id=zNWeBQAAQBAJ&printsec=frontcover&hl=es#v=onepage&q&f=false
But my output file does not have to do with this image.
Any idea / help?
Thanks in advance.
For your data, you don't need a histogram. Horizontal bars are sufficient. Instead of rotating a graph with plotting style with boxes you can use the plotting style with boxxyerror.
Make sure that your data separator is TAB or put your labels into "...".
### horizontal bars
reset session
set colorsequence classic
set datafile separator "\t"
$Data <<EOD
# index, purity, name
1 98 Ti/Si/TiC
2 94 Ti/TiSi_2/TiC
3 93.6 Ti/Si/C
4 92 Ti/SiC/TiC
5 93 Ti/SiC/C
6 98 Ti/Si/C + Al
EOD
unset key
set xlabel "Ti_2SiC_2 content, wt%" enhanced
set xrange [90:100]
set ylabel "Powder mixture"
unset ytics
set yrange [0:7]
set style fill solid 1.0
plot $Data u 2:1:(0):2:($1-0.4):($1+0.4):1 with boxxyerror lc variable,\
'' u 2:1:3 with labels offset 1,0 left
### end of code
Result:
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
I am using gnuplot in version 5.0 in order to plot graphs from Log files which are received from another script. Initially, a script runs which creates the Log files, and inside the same script (upon finishing) a new script which will plot the graphs is executed by receiving some command line arguments.
One of the command line argument for the plotting graph script ($4 specifically) is the path where the data (which will be used by plot command) is located. Upon finishing of execution:
line 0: warning: Cannot find or open file "/comperative_data.txt"
where the command line argument is not used at all. See the source code of the script below:
gnuplot<<EOF
set size 1.0,1.0;
set terminal postscript landscape color "Times-Roman" 14 linewidth 2
set timestamp "%d/%m/%y %H:%M"
set key left top Left noreverse enhanced box linetype -1 linewidth 1.000 sample 4 spacing 1 width 0 height 0 autotitles
set grid back lt 0 lw 1
set xlabel "TCP Window Size (Bytes)"
set ylabel "Average Transfer Speed (KiB/s)
set xtics (131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432)
set xtics rotate
set logscale x
set format x "%10.f"
set yrange [0:5000000]
set output "$filename"
set title "$title"
fileLocation=system("echo $4/comperative_data.txt")
plot fileLocation using 1:2 title 'Streams_1' with linespoints, fileLocation using 1:3 title 'Streams_2' with linespoints , fileLocation using 1:4 title 'Streams_4' with linespoints , fileLocation using 1:5 title 'Streams_8' with linespoints , fileLocation using 1:6 title 'Streams_16' with linespoints , fileLocation using 1:7 title 'Streams_32' with linespoints , fileLocation using 1:8 title 'Streams_64' with linespoints
EOF
I have been following various tutorials on how to run gnuplot and I have come up with this script. So far it is going well enough but when I try to change the offset on the xlabel or ylabel I get a message saying this in the terminal:
gnuplot> set xlabel "Applied Current [mA]" -0.3
^
line 0: ';' expected
I was wracking my brain so I even tested example xlabel and ylabel off the internet and the same type of error came up
#!/bin/bash
gnuplot << TOEND
# Set the output file
set terminal postscript eps color enhanced
set output 'fp.eps'
unset key
set title "Voltage as a Function of Current"
set noborder
set xtics axis
set ytics axis
set format x "%2.0f"
set format y "%2.0f"
u(x)=m*x+b
fit u(x) "nfp.dat" using 1:2 via m,b
v(x)=m*x+b
fit v(x) "wfp.dat" using 1:2 via m,b
set xzeroaxis linestyle 2 lt 1 lc 0
set xlabel "Applied Current [mA]" -0.3
set yzeroaxis linestyle 2 lt 1 lc 0
set ylabel "Voltage [mV]"
set xrange [ -15.00 : 15.00 ]
set yrange [ -20.0 : 20.0 ]
plot 'nfp.dat' using 1:2, \
v(x), 'wfp.dat' using 1:2, \
'sfp.dat' using 1:2
TOEND
convert -density 100 fp.eps fp.png
I think you are missing the offset flag. Try:
set xlabel "Applied Current [mA]" offset -0.3