set gnuplot precision for a specific column - gnuplot

I have a data file with 3 columns and I'd like to plot a 2D map plot. What I do in gnuplot is:
p'datafile' u 1:2:3 with image
for some set of data, the data on the 3rd column (say Z) are different with order of 0.01, e.g 1.56, 1.58, 1.59 etc. I'd like to skip those small difference and consider them all 1.5. How can I set gnuplot to consider only up to one digit after decimal for 3rd column? Thanks!

You can use the floor function to round your numbers down:
plot 'datafile' using 1:2:(floor($3*1e1)/1e1) with image
This sets all your numbers to 1 decimal place. If you wanted to do the same thing for a higher number of decimal places, you could change the 1e1 to 1eN, where N is the number of decimal places you want.

Related

gnuplot: Replace decimal point by another character

Using gnuplot v4.6.6:
To increase the available space for the actual graph I want to reduce the space required by the y-axis label to the bare minimum.
I'm now using: set format y "%4.1s%c".
Which results in labels like 500.0k. It would be nice if I could reduce this by one more character resulting in labels that look like this : 500k0
However, I can't figure out how to get this. Can it be done, and if so: how?
Thanks for your help.
EDIT: Here's an example graph of what I have now:
For this graph I use set format y "%3.0s%c" which is okay most of the time. But in some cases an extra decimal would be helpful.
You can modify the decimal character:
set decimalsign 'k'
Update:
Or you could plot log10(bits/s);
set yrange[0:9]
set ytics 1
plot 'data.d' using 1:(log10($2))
That would represent everything between 0 bits/s and 10^9 bits/s with a single digit on the y axis...

Creating basins of attraction from data file

How can Newton's basin of attraction be created from a data file?
I got 10000 points in the range -2, 2 and their zeros for complex function z^3-1. I'd like to plot them with three different colors to create basin of convergence.
Data I've obtained from my program is available here. The format is like this:
(-0.422468,1.36075) (-0.5,0.866025)
(1.19376,1.1324) (1,-6.76273e-19)
...
First two numbers in "( )" are complex start points, the second two are the zero that it converges to. Zeros are exact to the level of e-10, I can easily change it to e-16.
From what I understand, I would try something like:
plot 'yourdata.dat' using 1:2:(arg($3+$4*{0,1})) '(%lf,%lf) (%lf,%lf)' palette
The string '(%lf,%lf) (%lf,%lf)' is the format of your data, so that gnuplot can read it as a file of four columns. Then, you can select the columns to be plotted with using 1:2:(arg(...)); in this case, the x-axis is the real part of the starting points (column 1), and the y-axis is its imaginary part (column 2). The third part of using, arg($3+$4*{0,1}), and the option palette are used to chose the color depending on the phase of the complex zero (columns $3 and $4).

Comparative histogram of two data files, one with frequency, the other with boxes

I have two sets of data, and aim to make a comparative histogram from them. However one is a two-column data, x and its frequency, the second one is a one-column unsorted data which gnuplot should derive out the frequencies. I want a continuous histogram, but whatever I find on the web has gaps.
how should I do this?
I tried using the following script
binwidth=5
bin(x,width)=width*floor(x/width)
plot'data1.txt' with boxes, 'data2.txt' using (bin($1,binwidth)):(1.0) smooth freq with boxes
with the data files data1.txt:
1 3
5 1
7 1
and the second data file data2.txt:
1
1
1
5
7
This doesn't give the expected result.
Use the smooth frequency option, which makes the data monotonic in x; points with the same x-value are replaced by a single point having the summed y-values. So, if you use the first column as x-values and 1 as y-value you get the count:
plot 'secondfile.dat' using 1:(1) smooth frequency with linespoints
The plotting style is almost independent of the plotting style, so you can use points, lines, boxes etc.

How to plot graph with calculating average on abscissa in gnuplot

My data-file is formatted as fallows:
100;2.123;4.123
100;2.113;5.213
100;2.544;6.234
100;2.324;4.234
200;2.543;3.123
200;2.543;5.123
...
First column is a parameter of a function, second and third are the result of a function. The values of 2nd and 3rd are different for the same values of 1st column, because of other factors, and I want to plot a graph that calculates arithmetic average for all values from 2nd and 3rd column that have the same 1st.
Is there any way gnuplot can do this?
To calculate the arithmetic average of all values which share the same 1st value, you can use smooth unique. To get the average of all values of the 2nd and 3rd column for the same abscissa, you can use
set datafile separator ';'
plot 'datafile' using 1:(($2+$3)/2.0) smooth unique
That makes the data monotonic in the x-values and then replaces all points with the same abscissa with one point having the averaged y-value.
If e.g. you want only the averaged values of the 2nd columns, you would instead use
plot 'datafile' using 1:2 smooth unique
yes !
First of all replace each ; by a blank then
try this command
plot "your_data_file" using ($1):(($2+$3)/2)

Custom x-axis scaling for specified ranges using "weights"

I have a series of numbers in a file that I can already plot using gnuplot.
The tricky question: I have a bunch of ranges (positions), like
1-11
12-50
51-500
500-512
From this I can calculate the length of the actual range. Based on this lenght, I want to dynamically scale the x-axis for that actual range. Bigger length should produce more "compression" on the x-axis.
I am not sure I understand your question. Does
set xrange [51:500]
do what you want?

Resources