Gnuplot xticlabels with several lines - plot

if I add a xticlabel that uses 3 lines gnuplot cuts at the middle of the second line.
Is there any method to have xticlabels with several lines?
This is my data file:
"[17h30,19h00] 25" 1
"[03h30,10h00] 21" 1
"[03h00,12h00] 26" 2
"[18h00,19h30] 27" 3
"[20h30,22h00] 25" 4
"[13h00,14h30] 25" 4
"[19h30,21h30] 25" 5
"[14h30,16h00] 25" 5
"[16h30,18h00] 25" 5
"[09h30,15h00] 25" 9
And this is my gnuplot code:
set terminal postscript eps color
set output '| epstopdf --filter --outfile=hist.pdf'
set auto x
set yrange [0:10]
set style histogram clustered
set boxwidth 0.95 relative
set style fill transparent solid 0.5 noborder
plot 'hist.dat' using 2:xticlabels(1) with boxes lc rgb'blue90' notitle
Finally this is the graph produced:

Potential Problem 1: xtics overlap
You have a few options to help fix the xtic problem.
1) Rotate the xtics
set xtics rotate by -45
This will set the xtics to print at an angle from top-left to bottom-right.
2) Change the font size
set xtics font ",4"
You could make the font size tiny but unreadable.
3) add a gap between the bars of the graph
set style histogram gap 4
4) Change the data file
If you have control over the data file, you could try inserting some newlines into the xtic labels, e.g.
"17h30\n19h00\n25" 1
Potential Problem 2: xtics too long in general
I'm not quite sure from your question, but you may be running into this issue. Gnuplot has a built-in limit for the number of characters in a label, which is set to 50 in older versions of gnuplot and is 200 more recently. The post I linked to includes a workaround, which is to compile a version of gnuplot with an increased MAX_ID_LEN constant.

I had a similar issue, but in my case the labels where taken from two columns (a stringcolumn(1) and a numeric column(2)), while y-data in 3-rd column.
I split the labels in two using newline "\n"
using 2:3:xticlabels(stringcolumn(1) . "\n\n" . stringcolumn(2))
Basically inside xticlabels() you can give any string expression, for example
i also needed some numeric formatting for which i used instead of stringcolumn(2) the following expression:
gprintf('%1.0t*10^{%S}',column(2))
hope it helps

Related

How to fix xtics label overlapping in gnuplot

I'm using GNUPlot to draw the graph of five real-valued functions. I think it is easy to solve, but I am a beginner.
My x-axis has problems with its label. All the xtics numbers are overlapping, and I have no idea why.
My .plt plots 3 files: an .eps, an pb .eps and a .png. It receives a .100 file, which is 6 columns of numbers. The first column represents values for t and the other five columns represent values for each function at respective t.
My .plt file is:
reset
set terminal windows
set style line 1 lt 1 linewidth 3
set style line 2 lt 2 linewidth 3
set style line 3 lt 3 linewidth 3
set style line 4 lt 4 linewidth 3
set style line 5 lt 5 linewidth 3
set style line 6 lt 6 linewidth 3
set border linewidth 3
set xzeroaxis
set yzeroaxis
set xlabel '{/Helvetica-Oblique t (dias)}' enhanced font ',28'
set key center top
set key center right
set key top right
set key box
set tics scale 1.5
set grid ytics
set grid xtics
set xtics 0,250,3500
set ytics 0,0.1,1
set title 'Simulacao' font ',26'
set samples 100
plot "./fort.100" using 1:2 with lines title 'Ms' linestyle 1, \
"./fort.100" using 1:3 with lines title 'Mi' linestyle 2, \
"./fort.100" using 1:4 with lines title 'A ' linestyle 3, \
"./fort.100" using 1:5 with lines title 'H ' linestyle 4, \
"./fort.100" using 1:6 with lines title 'I ' linestyle 5
pause -1
set terminal postscript eps enhanced
set termoption enhanced
set output "xsol-pb.eps"
replot
set terminal postscript eps enhanced color font ',22'
set termoption enhanced
set output "xsol.eps"
replot
set terminal png giant size 900,600 enhanced
set termoption enhanced
set output "xsol.png"
replot
Link for my .eps graph:
How can I fix this problem?
I am also having a problem with the table, at the right top corner of the image. How to fix that?
Two possibilities to avoid "collisions" of data and key:
adjust your scale such that the curve is below the key, in your case e.g. set yrange[0:1.5]
shift the positon of your key, e.g. set key center right or set key at graph 0.8, graph 0.8. Check help key for more information.

rangelimited x-axis gnuplot disappears

I am trying to make a figure in gnuplot, similar to the bottom one on this page. Specifically, I only want an x- and y-axis on my figure at the places where there is data plotted.
For the y-axis, this works very well using the ytics rangelimited option. However, when I use xtics rangelimited on the x-axis, the x-axis border disappears:
Even more strangely, when I remove the set border option, there appears a diagonal line on my graph:
The minimal working example to make these figures is:
set terminal epslatex standalone size 8.0 cm, 8.0 cm
set output "test.tex"
# Define function
f(x) = abs(x)< 1 ? x**2 : NaN
set border 1+2 front #comment this out to get the diagonal line
set xrange [-1.5:1.5]
set xtics (-1.0,0,1.0) rangelimited nomirror
set yrange [-0.25: 1.25]
set ytics rangelimited nomirror
# plot line
plot f(x) with lines
I would like to get for the x-axis a similar result as for the y-axis. Does anyone know how to solve this problem?
As a side-question: I would like to have the 0 displayed on the y-axis as well. Is there any automatic way to do this? Or should I always explicitly tell gnuplot to put a tic at 0?
The rangelimited x axis is only drawn to span data points. You have no data points because you are plotting a function. In order to have the plot behave as a data plot rather than as a function plot you can use the following convention:
plot '+' using 1:(f($1)) with lines
See gnuplot documentation for "plot special-filenames"

Y-axis tick labels are the same

I am trying to plot some data and I noticed that the y-axis tick values were all the same. I tried to add more precision using y format, but it did not work. I am unsure what I may have done wrong.
I initially thought that the plots were reflective of the data, but I discovered that the values were all the same. What was initially confusing was that the y-axis just shows the same repeating value on the major tics.
There is another similar question on StackOverflow (Repeating y-axis tick labels), but the solutions there did not work for me, and I would like to understand why gnuplot does this (which is also not explained in the other question).
%> gnuplot -V
gnuplot 4.4 patchlevel 3
set term png font 'Liberation Sans,10' size 800,200
set output "data/plotid09-" . timestamp . ".png"
set style line 1 lt 1 lw 1 lc rgb "purple" pt -1
set xlabel "Time" font 'Liberation Sans,10'
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set xtics font 'Liberation Sans,10'
set ytics font 'Liberation Sans,10'
set format y "%8.4f"
set ylabel "Kelvin"
plot "data.txt" using 1:6 ls 1 smooth bezier with lines title "Temperature"
I found the problem. Thanks for the comments and feedback.
Changing the line
plot "data.txt" using 1:6 ls 1 smooth bezier with lines title "Temperature"
to
plot "data.txt" using 1:6 ls 1 with lines title "Temperature"
fixed the issue. The problem was the "smooth bezier" option. I removed it and the problem went away, I saw a flat line and appropriate numbering on the major ticks as seen below. The plot below is an example of what one of the fields look like now (similar data, same issue).
#

gnuplot: Row stacked bar graph with error bar

I am new to gnuplot. I want to generate graph from data points with three components and standard deviation.
My data looks like this:
TYPE1 15 20 65 5
TYPE2 20 20 60 4
TYPE3 10 30 60 6
TYPE4 30 30 40 5
I want to plot a rowstacked bar for each TYPE with the 3 components stacked and an errobar at the top.
I wrote the following script to do this:
set terminal png
set output "sample.png"
set boxwidth 0.75 relative
set style fill pattern 0 border
set style histogram rowstacked
set style data histograms
set xtics 1000 nomirror
set ytics 100 nomirror
set noytics
set mxtics 2
set mytics 2
set ytics 100
set yrange [0:150]
set ylabel "Y"
set xlabel "X"
set title "Sample graph"
plot 'data.dat' using (100*column(2)/(column(2)+column(3)+column(4))) t "A" , '' using (100*column(3)/(column(2)+column(3)+column(4))) t "B" , '' using (100*column(4)/(column(2)+column(3)+column(4))):xtic(1) t "C"
This produced a graph which looks like this: .
But I am not able to get the errorbar on the top of each bar with deviation values in column 5. I tried different ways using rowstacked and errorbar styled bar graphs but had no luck.
For this you must know, that with the histogram style the boxes are placed at the x-positions 0, 1, etc. i.e. at the row number.
So for the errorbars you must use column(0) as x-coordinate:
set terminal pngcairo
set output "sample.png"
set boxwidth 0.75 relative
set style fill pattern 0 border
set style histogram rowstacked
set style data histograms
set yrange [0:150]
set macros
scale = '100/(column(2)+column(3)+column(4))'
set bars 2.0
plot 'data.dat' using ($2 * #scale):xtic(1) t "A" , \
'' using ($3 * #scale) t "B" , \
'' using ($4 * #scale) t "C",\
'' using 0:(100):5 with errorbars notitle lw 2 lt -1
The result with 4.6.3 is:
For convenience I used a macro scale. The macros work as follows: You define a string, like scale = '...' in the script above. That can be used later in any expression as #scale (you must have set macros enabled). The content of the scale string is then replaced before the respective command is executed.

gnuplot: making axes numbers smaller in epslatex makes my axes label disappear offscreen

I'm writing a script to generate three plots in a column (using multiplot and setting margins). They all share an x-axis, so it's only necessary to label that on the bottom plot, but they have separate y-axes.
I'm using the epslatex terminal in gnuplot to generate the plots with latex labels and axes. Basically, I need the numbers on the axis to use a smaller font size than the actual axis labels. So far, I've been doing this using,
reset
set term epslatex standalone color solid 10
set output 'myplot.tex'
set multiplot;
#Common width for all three plots is set
set lmargin at screen 0.15;
set rmargin at screen 0.90;
set format x ""; #Removes xlabels from plots without removing tic marks
#First plot
set tmargin at screen 0.98;
set bmargin at screen 0.72;
set ylabel '$Label Name 1$';
set format y '\scriptsize{%g}';
plot "mydata.dat" u 1:3 w l lt 1 lw 3
#Second plot
set tmargin at screen 0.70;
set bmargin at screen 0.44;
set ylabel '$Label Name 2$';
set format y '\scriptsize{%g}';
plot "mydata.dat" u 1:11 w l lt 2 lw 3
#Third plot
set tmargin at screen 0.42;
set bmargin at screen 0.16;
set xlabel 'Common Label Name';
set format x '\scriptsize{%g}'; # Here I reset the x axis so it shows on
this plot
set ylabel 'Label Name 3';
set format y '\scriptsize{%g}';
plot "mydata.dat" u 1:5 w l lt 3 lw 3
unset multiplot;
So as you can see I use latex to format the numbers in a different size, specifically \scriptsize. For the xlabel at the end, everything works fine; the numbers are at a smaller font, and the xlabel prints just beneath it at the regular size. For the ylabels, however, the numbers DO appear smaller, but the actual label names don't appear on the plot.
At first I though they weren't being acknowledged somehow, but when I experimented with the margins, I found that if I move lmargin to the middle of the page, the ylabels reappear! It seems, for whatever reason, they're just being drawn some large distance from the axes themselves.
I've tried setting the labels with an offset, but that yields no joy.
The reason for this behaviour is, that gnuplot doesn't know, how the tics with LaTeX syntax will ultimately look like. The program tries to estimate the tic label length and adjusts the label positions accordingly.
If you have a format '\scriptsize %g', the tic labels seem to be very large:
set terminal epslatex standalone
set output 'label-offset.tex'
set format y '\scriptsize %g'
set ylabel 'ylabel'
plot x
set output
system('latex label-offset.tex && dvips label-offset.dvi && ps2pdf label-offset.ps')
Gnuplot version 4.2.6 doesn't consider the \scriptsize at all and you need a very large offset to compensate it: set ylabel 'ylabel' offset 14.
Since versoin 4.4 the behaviour is better, you need an much lower offset: set ylabel 'ylabel' offset 4.
Some remarks:
\scriptsize is a switch and doesn't take an argument. Consider set xlabel '\scriptsize{scriptsize} normal?'. To limit its effect, surround the text with brackets, like {\scriptsize %g}. But that is not necessary for tic labels, since they are in any case put in brackets.
To have italic text, use \textit{label name 1}, and not the math mode with $-signs.

Resources