gnuplot gives me strange plot look - gnuplot

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"

Related

Default weighing criterion for gnuplot's 'lc palette'

I'm a novice in Gnuplot. Today I was plotting a simple txt file with two data columns, being the x and y coordinates of a cloud of points in the xy plane; I wanted to color them according to the position they occupied in the list, so I should have gone for something like:
plot "data.txt" u 1:2:0 lc palette
that produces what I want:
(desired plot)
By mistake, I omitted the "using" part of the command, so that I prompted:
plot "data.txt" lc palette
Now, the points still are plotted in the correct positions, so that gnuplot is automatically interpreting them as (x,y) coordinates... but the colors look like this:
(strangely colored plot)
I find this baffling since there's the possibility that I'm involuntarily highlighting some interesting feature of my data (which, by the way, consists of few iterations of a discrete recurrence for a set - the x=1.57 line you can see - of different initial conditions.
The question is: what criterion does 'lc palette' use to assign the parity I see to my points? What is its default behavior supposed to be in this case?
Thanks in advance!
EDIT: I don't know if it can be useful, but prompting 'show palette' I get:
palette is COLOR
rgb color mapping by rgbformulae are 7,5,15
figure is POSITIVE
all color formulae ARE NOT written into output postscript file
allocating ALL remaining color positions for discrete palette terminals
Color-Model: RGB
gamma is 1.5

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}$.

Plotting heatmaps in gnuplot

So, here I am trying to plot heatmaps in gnuplot. I have a matrix-formatted text file (with row and column headers), and the command I am using to plot it is
plot "file.txt" matrix rowheaders columnheaders using 1:2:3 w image notitle
The output is this graph:
Obviously, the X and Y labels are useless like this. I believe the problem here is that gnuplot is extracting all labels from the file and plotting them. How would I go about reducing the amount of clutter in here, e.g. plotting every 10th label or so?
Thanks in advance.
Or just make the picture resolution bigger... for instance like 1920,1080 or bigger... like this:
set term pngcairo size 1920,1080
or make the tics numbers like 1000000 smaller and make a label to show that the numbers written on the tics are 1000000 bigger... or both:)
Sorry for my english...

gnuplot: numerical values of points of a function

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

Gnuplot: automatic placing of x2 tic labels

I've got data that I want to plot in gnuplot that looks something like this:
1.08 1 4.8
1.53 2 5.9
2.11 3 5.1
2.60 4 6.0
Not that it's terribly important, the first column is the running time of a genetic algorithm, the second column is the generation number, and the third is average fitness.
If I plot it using plot datafile.dat using 1:3 with lines it looks fine, with tics appropriately spaced. However, while I want the x-tics to be labelled with the time, I want the x2-tics to be labelled with the generation number. This is easy to do with plot datafile.dat using 1:3:x2ticlabels(2) with lines, but for the x2-axis it adds a tick for every single line in the data file, instead of automatically choosing an appropriate number of tics.
My full data file has thousands of entries, which results in a solid black line at the top of the graph where the tics would be spaced, and a larger solid black line above where the labels would be placed. Even if I try to manually tell gnuplot how often to place tics on the graph using set x2tics 100 it still displays them for every entry. Is there a way to fix this? Obviously I'd prefer which tics are shown to be automatically chosen, but if I have to do it manually that's fine. The full gnuplot config file is pretty basic, just:
set logscale y 10
set x2tics
plot datafile.dat using 1:3:x2ticlabels(2) with lines
Here's a solution that will only put a label for every other line in the datafile.
plot 'test.dat' u 1:3:x2ticlabels(int($0)%2==0?stringcolumn(2):'')
One thing that is a little interesting is that the tics don't quite line up with the points. I haven't figured out why yet. With thousands of points, you're probably not likely to notice, but with your example datafile with 4 points, it's noticeable.
Unfortunately, it still draws a tic on the axis for every line in the datafile. set x2tics scale 0 will make those tics go away completely.

Resources