I am trying to use gnuplot to plot results from my experiments.
I wrote a C++ program that generates a datafile that looks like this:
10 3.5
11 3.5
12 3.5
13 3.6
What I am trying to do is to display the values of the first column of this datafile on the x-axis as powers of 2. It would look something like that (It doesn't have to look exactly the same):
http://i.stack.imgur.com/8BSLr.png
So with the datafile I posted, I want to have 2^10, 2^11, etc on the x axis.
Any idea how to do that?
I can change the format of the datafile if needed.
Thanks!
this is done relatively easy by manipulating the using specification:
plot datafile using (2**$1):2
If you do this, you'll probably also want a
set logscale x 2
set format x '2^{%L}' #<- enhanced text.
to make the plot look nicer.
Related
I am trying to change my scale on gnuplot. I had a file from which I am plotting the fifth and sixth columns, and I am trying to change the x axis to a log scale. I am using
set logscale <2>
but it is saing that 'x' is an invalid axis. Is there a way to find out what the "name" of my 'x' axis is so that I can use this command?
From your question it's rather hard to see what you exactly want. Comment if this isn't what you're looking for. It sounds like you want to set the x axis to logscale base 2. It's done this way
set logscale x 2
In general, this is the command
set logscale <axes> <base>
I can't seem to get gnuplot to properly plot my time data. (I'm using version 4.6, patchlevel 3.)
For an MWE (well, non-working...), the input file
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using ($1):($2) with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
produces the following output:
Apparently, gnuplot interprets the hours as seconds and ignores the rest. I have tried a bunch of other format strings (also single/double quotes), but gnuplot seems to ignore everything except the first number.
Is something wrong with my format, or is this a bug, or something else?
With $1 you explicitely select the numerical value of the first column, which bypasses any gnuplot automatism to interpret the column values as appropriate (as time value in your case). Simply use using 1:2:
reset
set xdata time
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
plot '-' using 1:2 with lines lw 3
15:36:12 1.0
15:43:17 3.0
16:12:02 2.0
e
Use the syntax $1 only when doing calculations with the actual numerical value in the respective column. $1 is a shortcut for column(1), gnuplot also knows stringcolumn(1) and timecolumn(1) for other purposes.
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"
I am trying to plot a column greater than 10, but I get an error when I use {}.. like in regular bash. How do I tell gnuplot to do this?
plot '../data.txt' using (${11}:$2)
Give these two possibilities a try:
plot '../data.txt' using 11:2
plot '../data.txt' using ($11):($2)
I am using gnuplot (Version 4.4 patchlevel 2) to generate rowstacked histograms, very similar to the example called "Stacked histograms by percent" from the gnuplot demo site at http://www.gnuplot.info/demo/histograms.html
I want to display the values of each stacked box within it.
I.e. I want to display the actual numerical value (in percent and/or the absolute number) of each box.
How can I do that?
How many numbers do you want to enter.
If it is just a few then have you tried
set label "label" at 2,3
If there are many then you can write a script to decide where to put the numbers - something like here
Plotting arrows with gnuplot
Don't know a way to do it by magic, although I am not very familiar with rowstacked histograms
Tom