Gnuplot 3d Bar Graph

I am looking for a way to build histograms in 3d to create something like this figure http://www.gnuplot.info/demo/surface1.17.png , but where each series is a histogram.

I am using the procedure here https://stackoverflow.com/a/3608/ ... and http://www.gnuplotting.org/calculating-histograms/ to create histograms, and it works fine in 2d. I mainly use commands

hist = 'u (binwidth*(floor(($2-binstart)/binwidth)+0.5)+binstart):(1) smooth freq w boxes plot 'data.txt' @hist 

Now, I would like to add several histograms to the same plot, but since they overlap in 2d, I would like to highlight them in 3D.

I tried to execute the following command (using the procedure described above)

 hist = 'u (1):(binwidth*(floor(($2-binstart)/binwidth)+0.5)+binstart):(1) smooth freq w boxes splot 'data.txt' @hist 

But gnuplot complains that the z values ​​are undefined.

I don’t understand why this would not put the histogram along the value 1 along the x axis with the bins along the y axis and plot the height on the z axis.

My data is formatted simply in two columns:

 Index angle 0 92.046 1 91.331 2 86.604 3 88.446 4 85.384 5 85.975 6 88.566 7 90.575 

I have 10 files like this, and since the values ​​in the files are close to each other, they will completely overlap if I put them all on the same 2nd histogram. Therefore, I would like to see 10 histograms one after another in a certain 3D perspective.

+2
plot gnuplot histogram
source share
2 answers

This second answer is different from my first. Considering that the first question that the OP is trying to fulfill, the second gives an alternative approach, which is aimed at eliminating the main problem that the OP was trying to overcome.

I posted an answer that discusses the possibility of doing this in 3d. However, this is usually not the best way to do this with a few histograms like this one. Such a three-dimensional graph will be difficult to compare.

We can address the overlap in 2D by slowing the position of the drawers. With default settings, boxes will be distributed to the touch. We can disable this and adjust the position of the boxes so that there are more than 1 histogram on the chart. Remember that the coordinates you supply are the centers of the boxes.

Suppose I have the data that you provided and this additional data set

 Index Angle 0 85.0804 1 92.2482 2 90.0384 3 99.2974 4 87.729 5 94.6049 6 86.703 7 97.9413 

We can set the window width to 2 units using set boxwidth 2 (your cells are 4 units). In addition, we will enable box filling with set style fill solid border lc black .

Then I can release

 plot datafile1 u (binwidth*(floor(($2-binstart)/binwidth)+0.5)+binstart):(1) smooth freq w boxes, \ datafile2 u (binwidth*(floor(($2-binstart)/binwidth)+0.5)+binstart+1):(1) smooth freq w boxes 

The second chart command is identical to the first, with the exception of +1 after binstart . This will move this block 1 block to the right. This gives

enter image description here

Here two episodes are clear. Keeping track of which cell is associated with each one is easy due to overlap, but not enough to mask other series.

We can even move them next to each other without overlapping by subtracting 1 from the first build command:

 plot datafile1 u (binwidth*(floor(($2-binstart)/binwidth)+0.5)+binstart-1):(1) smooth freq w boxes, \ datafile2 u (binwidth*(floor(($2-binstart)/binwidth)+0.5)+binstart+1):(1) smooth freq w boxes 

production

enter image description here

0
source share

This first answer is different from my second. This answer relates to what the OP tried to accomplish, while the second solves the main problem that the OP tried to overcome.

Gnuplot will not be able to do this on its own, since the corresponding styles (boxes and histograms) work only in 2D. You will need to do this with an external program.

For example, using your data and your 2d command (your first command), we get (using your data and the associated values ​​-100 and 4 for binstart and binwidth)

enter image description here

To draw these squares on a 3d grid, we will need to use the line style and have four dots for each: lower left, upper left, upper right and lower right. We can use the previous command and capture it in the table, but this will only give the top center point. However, we can use an external program for preprocessing. The following python makehist.py program does just that.

 from sys import argv import re from math import floor pat = re.compile("\s+") fname = argv[1] binstart = float(argv[2]) binwidth = float(argv[3]) data = [tuple(map(float,pat.split(x.strip()))) for x in open(fname,"r").readlines()[1:]] counts = {} for x in data: bn = binwidth*(floor((x[-1]-binstart)/binwidth)+0.5)+binstart if not bn in counts: counts[bn] = 0 counts[bn]+=1 for x in sorted(counts.keys()): count = counts[x] print(x-binwidth/2,0) print(x-binwidth/2,count) print(x+binwidth/2,count) print(x+binwidth/2,0) print(max(counts.keys())+binwidth/2,0) print(min(counts.keys())-binwidth/2,0) 

Essentially, this program performs the same function as the smooth frequency option, but instead of getting the top center of each window, we get the four previously mentioned points along with two points to draw a line along the bottom of all the boxes.

By running the following command

 plot "< makehist.py data.txt -100 4" u 1:2 with lines 

produces

enter image description here

which is very similar to the original graph. We can use this in 3D graphics.

 splot "< makehist.py data.txt -100 4" u (1):1:2 with lines 

which produces

enter image description here

This is not all so beautiful, but puts the histogram on a 3D plot. The same method can be used to add multiple data files to it. For example, with additional data

 Index Angle 0 85.0804 1 92.2482 2 90.0384 3 99.2974 4 87.729 5 94.6049 6 86.703 7 97.9413 

We can use

 splot "< makehist.py data.txt -100 4" u (1):1:2 with lines, \ "< makehist.py data2.txt -100 4" u (2):1:2 with lines 

for creating

enter image description here

0
source share

All Articles