How to get the values of the axes of plot image without x/y tics using GNUPlot? - plot

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

Related

How to control tic marks and their values in gnuplot tics

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:

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"

gnuplot: Joined axes with overlapping tics

A while back I found a method to join Axes in a nice way. Now that I revisit the plot-making for a report I find that I'm not satisfied...
The reason for this is the overlap between the labels at the tics of my plot. Since I joined the axes, the last of the left and first of the right plot tics will overlap, shown in the below example with random sin and cos plotted.
How can I circumvent this in a general way. Please note that I will be plotting a lot of figures like these in series, figuring out each of these tics depending on the values of my data is not an option for me.
Thanks in advance!
My plot-file: JointAxes.gp
# Generic gnuPlot script for plotting multiple plots in a single figure
# Resetting all variables. Standard for all plots.
reset
# Setting (terminal) options.
set terminal pdfcairo color font ",8"
set output 'JointAxes.pdf'
# Option to plot multiple graphs in one picture, note the number of figs here is 4 (2 by 2).
set multiplot layout 2,2 rowsfirst
# Macro's needed to produce a figure with all plots 'touching'.
set macros
# Small plot labels
LABEL = "at graph 0.9,0.9"
# Axes adjustment
set format x "%.1f"
XAXE = 'set xlabel "Extent"; set xtics -2*pi,pi/3 # N.B. tics should be changed due to conjoined axes.
YAXE = 'set ylabel "Amplitude"; set ytics -1,0.25
NOX = "unset xtics;\
unset xlabel"
NOY = "unset ytics;\
unset ylabel"
# Locking the graphs at fixed points in the figure
# Margins for each row resp. column
TMARGIN = "set tmargin at screen 0.90; set bmargin at screen 0.55"
BMARGIN = "set tmargin at screen 0.55; set bmargin at screen 0.20"
LMARGIN = "set lmargin at screen 0.10; set rmargin at screen 0.50"
RMARGIN = "set lmargin at screen 0.50; set rmargin at screen 0.90"
# General plot markup
unset key
# Legend/key adjustment
# set key samplen 3 # length of legend colour-bar
# set key spacing 1 # spacing between samples
# Optional: Adjusting range
set yrange [-1:1]
set xrange [-pi:pi]
# Plotting the first of the 'sub'-plot
#YAXE; #NOX
#TMARGIN; #LMARGIN
set label 1 'a' #LABEL
plot sin(x)
# Plotting the second 'sub'-plot, i.e. a new plot command.
#NOX; #NOY
#TMARGIN; #RMARGIN
set label 1 'b' #LABEL
plot cos(x)
# Plotting 3rd
#YAXE; #XAXE
#BMARGIN; #LMARGIN
set label 1 'c' #LABEL
plot sin(x + 1.57)
#And Fourth
#NOY; #XAXE
#BMARGIN; #RMARGIN
set label 1 'd' #LABEL
plot cos(x + 1.57)
unset multiplot
set terminal wxt
set output
# OEF

GNUPLOT: saving data from smooth cumulative

I make this simple cumulative and histogram plot of a uniform random distribution of real numbers (n=1000):
http://www.filedropper.com/random1_1: random1.dat
And the macro is:
unset key
clear
reset
n=120 #number of intervals
max=4. #max value
min=1. #min value
width=(max-min)/n #interval width
#function used to map a value to the intervals
bin(x,width)=width*floor(x/width)+width/2.0 # cosi viene centrato in mezzo
set xtics min,(max-min)/10,max
set boxwidth width
set style fill solid 0.5 border
set ylabel 'Frequency'
set y2label 'Cumulative frequency'
set y2tics 0,100,1000
set ytics nomirror
set xrange [0.9:4.1]
set yrange [0:25]
set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
set output "testCum.png"
plot 'random1.dat' using (bin($1,width)):(1.0) smooth frequency with boxes title 'histogram',\
'' using (bin($1,width)):(1.0) smooth cumulative axis x1y2 w l lt 2 lw 2 lc rgb 'green' title 'cumul'
Now the output.png is:
How I can tell to Gnuplot I want to take not only the cumulative plot but also the numbers coming from it saved in a particular file.dat ?
You can save the data after applying smooth with set table .... In the simplest case, if you need only the cumulative data, just use:
set table 'random1-smoothed.dat'
plot 'random1.dat' using (bin($1,width)):(1.0) smooth cumulative
unset table
For better inclusion in your script you could also wrap the whole, existing plot command in set table:
...
set table 'random1-smoothed.dat'
plot 'random1.dat' using (bin($1,width)):(1.0) smooth frequency with boxes title 'histogram',\
'' using (bin($1,width)):(1.0) smooth cumulative axis x1y2 w l lt 2 lw 2 lc rgb 'green' title 'cumul'
unset table
set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
set output "testCum.png"
replot

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