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"
Related
My plot has logx axis. So I want to show the tic marks. But due to the size of the tic values they overlap. For example:
But if I reduce the tic marks by the command
set xtics (1.0e-7,1.0e-5, 5.0e-4);
It becomes like
I want those logarithmic tics(like the first picture) but only three values written(like the second picture) without compromising the size. Is it possible?
As I understand you basically want keep all the auto tics and grid lines, but remove 1e-6 and 1e-4 tic labels and add a 5e-4 tic label.
You could do it the following way. Check help xtics and help format specifiers.
Code:
### set custom tics
reset session
set xrang[1e-7:5e-4]
set logscale x
set grid x,y
set format x "%.0t x 10^{%T}"
set rmargin 5
set xtics add ('' 1e-6, '' 1e-4, 5e-4)
plot x
### end of code
Result:
I want to make a PNG image of my plot but would like to overlay this on a map. To do this we need the boundary coordinates and a simple png without any axes or tic marks ending up in the image. I tried turning of the ticmarks by unset xtics / ytics but then the value of GPVAL_X_MAX becomes the same as GPVAL_DATA_X_MAX. Is there any way to find the min/max values of the plot without the using the tics?
Example:
plot [-10:10] sin(x),atan(x),cos(atan(x));
show variables all;
Gives GPVAL_Y_MIN = -1.50, GPVAL_Y_MIN=-1.47...
Whereas:
unset xtics;
unset ytics;
plot [-10:10] sin(x),atan(x),cos(atan(x));
show variables all;
gives GPVAL_Y_MIN = -1.47, GPVAL_Y_MIN=-1.47...
edit:
Fixed, I finally just removed all style/layout of the tics and scaled their size down to zero. This way GPVAL_X_MIN etc retain the value of the actual boundaries instead of the min/max vals of the dataset.
A simple brute force solution would be to plot twice. The first time with tics enabled, just to store the value of the variables you're after, such as GPVAL_DATA_Y_MIN. You can then plot a second time with tics disabled.
set terminal pngcairo
set output 'plot.png'
plot [-10:10] sin(x),atan(x),cos(atan(x));
y_min = GPVAL_Y_MIN
data_y_min = GPVAL_DATA_Y_MIN
unset xtics
unset ytics
set output 'plot.png'
replot
print sprintf("GPVAL_Y_MIN = %f", y_min)
print sprintf("GPVAL_DATA_Y_MIN = %f", data_y_min)
Output:
GPVAL_Y_MIN = -1.500000
GPVAL_DATA_Y_MIN = -1.471128
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).
#
I am trying to plot multiple plots on the same page of gnuplot postscript output. Although, I like the way the plots are looking, what can I do to avoid the text on the plots? (See the code below, and the plot too). If you cannnot see the text on the plot, it says: "'../binsam_Omidi.dat' using 5:($1==1?$6:1/0)"
reset
set term postscript eps color size 10,10
set output "../Results/phasespace_bins.ps"
set multiplot layout 4,5 # engage multiplot mode
set size square
set size ratio -1
plot '../binsam_Omidi.dat' using 5:($1==1?$6:1/0) w p ps 1 pt 7
set size 0.4,0.4 # set the size of the second plot in plot units
set origin 0.15,0.5 # set the origin for the second plot
plot '../binsam_Omidi.dat' using 5:($1==1?$6:1/0) w p ps 1 pt 7
unset multiplot
Thanks!
That is the legend (key) entry of the plot. You can specify your own title with the title option, like
plot x title 'my title'
If you don't specify your own title, the code of the plot command is used. This is what you see.
To have no key entry for a single plot use notitle or title ''. If you don't want to have any key at all use unset key.
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.