gnuplot: numerical values of points of a function - gnuplot

Is it possible with gnuplot (4.6) to print (in a file or through redirection from standard output) the values of the sampled points of a function.
Say, if I write plot sin(x) with for example set samples 20, I want 20 lines of data giving me the x,y values of the computed points that would be plotted.
I don't care if these are actually plotted or not.
I though that there was some kind of "text" terminal, but it seems that there is none.

This can be done with set table environment
For example:
set table "outputfile.txt"
plot sin(x)
unset table

Related

Editing y axis range in Gnuplot

I have a plot with exponential y axis range. I'm using multiplot command by inserting two images in one row. So due to this wide y axis range I'm loosing some space which I could use it to show my plots in a better way. I want basically something like this
How could i do this? I think for doing this I have do some math operations in the y axis range. Also what is the most convenient command to insert ( xE-10) at top left of the plot.
reset
set terminal epslatex size 16cm,18cm color colortext
set output new.tex
set key off
set format $%g$
set title "sinx"
set ylabel "[kNm]"
plot 1000000*sin(x)
This is not my exact code but it looks similar to this. The plot I have presented is a part of the multiplot code and I use 7 input files with time series data of 300 seconds at a time step of 0.02. The point I want to edit the y axis range (use some mathtematical expressions) and also include the term ( xE-10 ) on the top of the plot something like this
You can manually add the exponent with a set label .... For instance, the following function takes large values within the given interval:
plot[0:50] exp(x)
We can place the "x 10^21" manually in the desired place after dividing the plotted quantity by it:
set label 1 "{/Symbol \264} 10^{21}" at graph 0,1.025 left
plot[0:50] exp(x)/1e21
You have to be careful with the exact placement of the exponent since it might lie outside the plotting area, in which case you should lower the top margin with set tmargin .... Also, to use the "times" symbol, you need to pass the enhanced option to your terminal. With the epslatex terminal, you can use latex syntax: $\times 10^{21}$.

Gnuplot - Plot data on another abscissa by interpolation

Good evening,
I have a problem with Gnuplot. I tried to sum up my problem to make the comprehension easier.
What I have : 2 sets of data, the first one is my experimental data, about 20 points, the second one is my numerical data, about 300 points. But the two sets don't have the same abscissa.
What I want to have : I want my numerical data be interpolate on the x-experimental abscissa.
I know it is possible to do that with Xmgrace (paragraph Interpolation at http://plasma-gate.weizmann.ac.il/Xmgr/doc/trans.html#interp) but with Gnuplot ?
What I want to have in addition : is it possible, then, to subtract the y-experimental data of my y-numerical data at the x-experimental abscissa points ?
Thank you in advance for your answer,
zackalucard
You cannot interpolate the ordinate values of one set to the abscissa values of the other. gnuplot has no mechanism for that.
You can however plot both datasets using one of the smoothing algorithms (check "help smooth") with common abscissa values (which might (be made to) coincide with the original values of one set.)
set table "data1.tmp"
plot dataf1 smooth cspline
set xrange [GPVAL_x_min:GPVAL_X_max] # fix xrange settings
set table "data2.tmp"
plot dataf2 smooth cspline
unset table
Now you have the interpolated data in two temporary files, and only need to combine them into one:
system("paste data1.tmp data2.tmp > correlation.dat") # unixoid "paste" command
plot "correlation.dat" using 2:4
(If you have a sensible fit function for both datasets, the whole thing becomes much easier : plot dataf1 using (fit1($1)):(fit2($1)))
You can use smoothing, this should do the trick
plot "DATA" smooth csplines
(csplines is just one options, there others, e.g. bezier)
But I don't think you can automatically determine the intersection of the smoothed curved. You use the mouse to determine the intersection visually, or alternatively fit some functions f(x) and g(x) to your curves and solve f(x)=g(x) analytically

How do I use the columnhead (string) in a data file on the x-axis as a xiticlabel of a plot with boxes? (Gnuplot)

I´m new here and this is my first question, hope my Problem is described properly according to our rules in here...
I´ve got a data file (datafile.dat) which is used to create several plots (see below):
temp name1 name2
10 1000 1200
22 800 750
50 250 200
100 80 82
107 5 3
What I want to do is to create a plot with the values in the second and third column plotted with boxes. On the x-axis the names these values refer to shall be displayed. In Addition it shall be possible to give each of the boxes a specific colour. An additional Advantage would be that the solution can also be used in a Loop (because the original data file contains a lot more columns...).
In the end I want the graph to look something like this:
Desired Layout of the plot.
In order to get this I tried different things I found searching the Internet (see below). I am running gnuplot 5 on Windows with the following command file:
xticlabels
If I try this e.g. for column 2 this doesn´t work:
plot 'datafile.dat' u 2:xticlabels(columnhead(2))
Using an external utility
Didn´t work at all, failure message was produced
Stats
Looks like a pretty good solution if I store the output in a variable. But I can´t get my code working (see below):
reset
set terminal postscript eps size 15 cm, 15 cm colour enhanced dashed "Times, 22"
set output "test.pdf"
stats 'datafile.dat' using 2
b = STATS_sum
plot 'datafile.dat' u 2:xticlabels(b) every ::1
reset
What can I do to create the desired output from the data file above? I tried the Points mentioned above in many different combinations. Suggestion 1, Suggestion 2, Suggestion 3 are further Topic-related ideas to solve the Problem but I got none of these working. Can please anyone help me to get a solution? Any hints will be highly appreciated!!!
Thanks in advance!!!
Michael
EDIT: I found out that this question was already asked from someone else three years ago: Axis label and column header ...Is there maybe a solution today? Also: Question
I can see two methods for doing this. The first is more automatic, but has the disadvantage of not being able to do the colors.
Method 1
Using only one datapoint for each column (as your comment suggests you will be doing), we can almost accomplish this using the columnstacked histogram style. At this point, I'm not sure how to get different colors, as the columnstacked style applies colors to the sections of the stacks.
Using, your example data, and the first line of data, we can do
set style data histogram # we could do w histograms in the plot command instead
set style histogram columnstacked
set boxwidth 0.9 # so the boxes don't touch
set style fill solid
set key autotitle columnhead # first row contains series name
plot for[i=2:3] "datafile.dat" every ::0::0 u i
where every ::0::0 means use the 0th (first) line of data† only.
This produces
To plot columns 2 through 50, for example, just change the for[i=2:3] to for[i=2:50].
Method 2
We can do this by using the stats command to add the labels, and then do a standard plot command.
To set the tic marks, we can do
set xtics 1,1 format ""
do for[i=2:3] {
stats "datafile.dat" every ::0::0 u (a=strcol(i),1) nooutput
set xtics add (a i-1)
}
The first command here sets the xtics to occur every 1 unit starting at 1 but suppresses the labels (we will be setting our own labels).
We then loop over each column, reading the 0th line in the datafile with the stats command. When we read it, we store the columnheader in a variable a. We just return a 1 for the stats command to actually analyze. We actually don't care about the results of this command, we just need it to read the column headers. Finally, we use set xtics add to add this label as an xtic.
Next, we can do some necessary set up commands
set style fill solid
set boxwidth 0.9 # so the boxes don't touch
unset key
set yrange[0:*] # by default, the smallest boxes may be cut off
Finally, we can plot with‡
plot for[i=2:3] "datafile.dat" every ::1::1 u (i-1):i w boxes
The result is
Again, the for loops can be changed to use any number of columns. X-ranges can be adjusted if desired, and linetype commands can be used in the plot command to set colors.
† We use every ::0::0 because the set key autotitle command causes the first line with the column headers to be ignored (processed before the plot command). Thus the first (0th) line is the first line of actual data.
‡ Note that here we use every ::1::1 because the 0th line is the column header line. Without the set key autotitle command, the first line is not automatically ignored.

Gnuplot - how can I get a figure with no point on it ? (I want to have only the axes, the title and the x- and y- labels)

I have to create a video presenting the evolution of some quantities as functions of time. I am creating images with gnuplot and I assemble them to make a movie. I am getting trouble generating the two first images: the first image is supposed to have no point on it (it is supposed to show only the title of the graph, the x and y axes and the labels of the axes) and the second one is supposed to have one single point on it.
Is it possible to create a graph containing no data on it with gnuplot?
Is it possible to create a graph containing one single point with gnuplot using an input file? The input file contains:
0 15
Thank you in advance for your answers,
Julien
To plot an empty graph, just plot a completely undefined function like
plot NaN
The main issue here is, that the autoscaling fails since there are no valid points. You must give a fixed xrange and yrange to get a plot:
set xrange [0:1]
set yrange [0:1]
plot NaN notitle
Plotting a single point works fine using
plot 'file.dat' using 1:2 with points
You'll get warnings saying Warning: empty x range [0:0], adjusting to [-1:1] and Warning: empty y range [15:15], adjusting to [14.85:15.15], but you get a plot. To remove the warnings, you must again provide a fixed xrange and yrange.

gnuplot gives me strange plot look

I could not describe how the plot looks like so I just use "strange" as I have no idea why gnuplot gives me such a plot. Here is the thing I am trying to do.
I have a data file with two columns, the first column is the file name and the second is the size of each file. Each column is more than 2 million rows. I just want to plot the distribution of file sizes. Here is my code
set terminal postscript landscape enhanced mono dashed lw 2 "Times" 18
outputfile = "sizedist.ps"
set output outputfile
binwidth = 0.05
bin(x,width)=width*floor(x/width)
plot [0:3.5][]'sizedist.out' using (bin(log10($2/1024),binwidth)):(1.0) smooth freq with boxes t "Binsize=0.05 dex"
set terminal x11
Ideally, it should be a single Gaussian-like bar plot, but it has many other plots over-layed (see my attachment). Any expert on gnuplot knows why this happened?
This happens if some of your data in the frequency plot does not have well defined values (such as NaN, inf etc.).
Since you are using a logarithmic function in the plot, you have to be careful with data that has values <=0. I guess you have files with size=0. In this cases log10 just gives you NaN and this messes up the counting procedure of the frequency plot.
Include a condition to your plot to fix this. For example:
plot [0:3.5][]'sizedist.out' using ($2>0?bin(log10($2/1024),binwidth):0):(1.0) smooth freq with boxes t "Binsize=0.05 dex"

Resources