How can I (or can I) present this gnuplot histogram:
in this style of 3D histogram view - in gnuplot?:
Using the same data and data format as in the gnuplot example in answer would be best.
The questions of the OP: How can I ...
There are a few workarounds that produce an output resembling the sample that you show.
They do not have all the bells and whistles you may want for formatting, but they are approximations which look "ok".
As per http://lowrank.net/gnuplot/plotpm3d-e.html#6.9 , pm3d should do the trick for what you need.
See also pm3d down in this link.
If shading is essential, you can try using some of this. But you should work out quite a bit.
Another poor-man approximation to what you are asking for is given here.
I do not have gnuplot here to test these.
... (or can I)
It is widely documented that there is no facility for a 3D histogram plot, and anything to do a real such plot with the corresponding options (shading, spacing, back walls, perspective view, selection of point of view, etc.) requires complex user programming.
Closest thing available in gnuplot that doesn't involve significant hackery and/or preprocessing seems to be impulses style. The help docs even suggest their use for 3d bar charts:
To use this style effectively in 3D plots, it is
useful to choose thick lines (linewidth > 1). This approximates a 3D bar chart.
Here is a simple example using impulses, and matrix style data as in the linked heatmap example:
set title ''
unset key
set xyplane 0
set view 60,300,1.2
set xrange [-0.5:5]
set yrange [-0.5:5]
splot '-' matrix with impulses lw 20
0 0 0 0 0 0
0 1 2 3 4 5
0 2 4 6 8 10
0 3 6 9 12 15
0 4 8 12 16 20
0 5 10 15 20 25
e
The issue is gnuplot renders the impulses as 2d pen strokes. It would be ideal if there was a way to some how apply a 3d surface effect to those lines, but I don't think there is a way, since they are just lines, not surfaces.
You can also use vectors style to achieve similar result to impulses above, but with support for "rgb variable" (AFAIK impulses doesn't support this). This allows you to change color based on z-value - but still no 3d surface. You'll have to use a different data format for vectors style (AFAIK), but it's a simpler transform from matrix style data than some other hack require:
set xyplane 0
set view 60,301,1.2
set xrange [0.5:5]
set yrange [0.5:5]
rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
splot '-' using 1:2:(0):(0):(0):3:(rgb($3*(255/25),0,0)) with vectors nohead lw 40
5 5 25
5 4 20
5 3 15
5 2 10
5 1 5
4 5 20
4 4 16
4 3 12
4 2 8
4 1 4
3 5 15
3 4 12
3 3 9
3 2 6
3 1 3
2 5 10
2 4 8
2 3 6
2 2 4
2 1 2
1 5 5
1 4 4
1 3 3
1 2 2
1 1 1
e
Related
I would like to make a graphic like this, but I can not find similar information.
I have searched for examples on the internet, but the most I find are stacked graphs
!https://www.intechopen.com/media/chapter/54498/media/F1.png
The first thing is that you have the data in some useful format.
Since it will be probably an extra effort for gnuplot to group the values into your material categories (but can also be done), it is easier if you give numbers to each of your material categories. Then just plot points and labels. Do not hesitate to post the data and show your code how far you actually got.
Code:
### plot with labels
reset session
$Data <<EOD
Pt Metal 1 1750
Graphite Metal 1 3600
B_4C Carbide 2 2450
HfC Carbide 2 3800
Si_3N_4 Nitride 3 1900
HfN Nitride 3 3300
W_2B_5 Boride 4 2250
HfB_2 Boride 4 3400
Y_3Al_5O_{12} Oxide 5 1950
ThO_2 Oxide 5 3050
TiSi_2 Intermet. 6 1550
Zr_5Si_3 Intermet. 6 2250
Ti_3SiC_2 "Ternary\nComp." 7 1400
(Hf,Ta)C "Ternary\nComp." 7 3600
EOD
set bmargin 3
set xrange[0.5:8]
set ylabel "Melting temperatures (°C)
set yrange[1000:4500]
set grid xtics, ytics
plot $Data u 3:4:xtic(2) w p pt 7 notitle,\
'' u 3:4:1 w labels left offset 1,0 notitle
### end of code
Result:
I am trying to plot a 'heatmap' and 'a cut of that heatmap' at a specific position using the data at the bottom. I would like to use use the every command in gnuplot to do so, but I fail. every ::13::17: is supposed to plot data from the line 13 to line 17. I am getting an error from gnuplot.
reset
set terminal pngcairo
set output 'stack.png'
set palette defined (0 "white", 1 "red")
unset key
set style fill solid
#----------------- 2D plot ---------------
plot 'stack.dat' using 1:2:(log10($3)) with boxes linecolor palette notitle
# ---- PLot a section of the 2D plot ----------
set output 'oups.png'
plot 'stack.dat' using 2:(log10($3)) every ::13::17: with lines notitle
'stack.dat' is the datafile name
1 1 0.081051938235759735
1 2 0.039051856845617294
1 3 0.017708625644445419
1 4 0.053782138973474503
1 5 0.069525197148323059
2 1 0.046054631471633911
2 2 0.005992549471557140
2 3 0.010819308459758759
2 4 0.001308800885453820
2 5 0.032604649662971497
3 1 0.078480839729309082
3 2 0.000435109512181953
3 3 0.073167815804481506
3 4 0.052882101386785507
3 5 0.016808584332466125
4 1 0.060769289731979370
4 2 0.028200428932905197
4 3 0.031424820423126221
4 4 0.052520859986543655
4 5 0.078694045543670654
5 1 0.029850590974092484
5 2 0.027807384729385376
5 3 0.036195535212755203
5 4 0.026242787018418312
5 5 0.048620097339153290
How can I make it works?
Is there a better way to plot sections of heatmap?
The short answer is to use
plot 'stack.dat' using 2:(log10($3)) every :::2::2 with lines notitle
When you have multiple blocks of records there is a distinction between lines in a datafile and records. So in order to specify a data sequence, you need the block and record indexes. Check the docs for more info (see Every): http://gnuplot.sourceforge.net/docs_5.2/Gnuplot_5.2.pdf
I have a data file that I am creating a histogram from.
The data file is :
-0.1 0 0 JANE
1 1 1 BILL
2 2 1 BILL
1 3 1 BILL
6 4 0 JANE
35 5 0 JANE
9 6 1 BILL
4 7 1 BILL
24 8 1 BILL
28 9 1 BILL
9 10 0 JANE
16 11 1 BILL
4 12 0 JANE
45 13 1 BILL
My gnuplot script is :
file='test.txt'
binwidth=10
bin(x,width)=width*floor(x/width)
set boxwidth 1
plot file using (bin($1,binwidth)):(1.0) smooth freq with boxes, \
file using (1+(bin($2,binwidth))):(1.0) smooth freq with boxes
I would like to plot this data on a logscale in y. However there are some 0 values (because some of the bins are empty) that cannot be handled by set logscale y. I get the error Warning: empty y range [1:1], adjusting to [0.99:1.01].
According to gnuplot's help, "The frequency option makes the data monotonic in x; points with the same x-value are replaced by a single point having the summed y-values."
How can I take the log10() of the summed y-values computed by smooth freq with boxes?
There are at least two things that you could do. One is to use a linear axis between 0 and 1 and then use the logarithmic one as explained in this answer. The other one is to plot to a table first and then set the log scale ignoring the points with zero value.
With a normal linear axis and your code (plus set yrange [0:11]) your data looks:
Now lets plot to a table, then set the log scale, then plot ignoring the zero values:
file='test.txt'
binwidth=10
bin(x,width)=width*floor(x/width)
set table "data"
plot file using (bin($1,binwidth)):(1.0) smooth freq, \
file using (1+(bin($2,binwidth))):(1.0) smooth freq
unset table
set boxwidth 1
set logscale y
set yrange [0.1:11]
plot "data" index 0 using ($1):($2 == 0 ? 1/0 : $2) with boxes lc 1, \
"data" index 1 using ($1):($2 == 0 ? 1/0 : $2) with boxes lc 2
set table sometimes generates some undesirable points in the plot, which you can see at x = 0. To get rid of them you can use "< grep -v u data" instead of "data".
I have a set of data to plot using histogram bars. I want the bars to be shaded in lines but not filled with colros like red, blue or any other colors. The sample data is as below:
1 23 2 9 13
2 25 5 7 12
3 26 5 3 13
4 20 6 8 5
5 23 5 12 15
6 23 5 12 11
7 22 9 12 5
8 24 16 5 8
9 23 2 12 10
10 23 15 5 9
I have the sample code as well,
set terminal jpeg medium
set output "histo.jpeg"
set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set style histogram rowstacked
set style data histograms
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:50]
set ylabel "Total time"
set xlabel "Session number"
plot 'papa2.dat' using 3 t "Server", '' using 4 t "Client", '' using 5:xtic(1) t "Network"
But when I use this I get bars in histogram filled with colors.
Can anyone help me to on how to plot the graphs in lines instead of colors?
Many thanks in advance.
(note: I got these sample data and code from internet)
I wonder what you want is something shown in the first figure of this page: histograms.dem.
If that is the case, you can either do set style data linespoint as shown in the demo page, or plot 'papa2.dat' using 3 t "Server" with line when you use the plot command.
Note that you have a lot more demo scripts available in the gnuplot project website: Demo scripts for gnuplot 4.4
I have a data set that uses the x-scale:
0.1 0.4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
But I need the tics to line up evenly, not have 0.1 and 0.4 scrunched up into the corner. I currently use,
set xtics 1
set xtics add (0.1)(0.4)
But that spaces 0.1 and 0.4 respective to the rest of the scale. I've attached a link to a tinypic I uploaded of my dummy data set with my current problem.
http://tinypic.com/r/2zfolxf/7
Current State
As far as I know, you can do the following in gnuplot with tics (at least what is relevant to your question):
You can specify the start, increment and end of the tics displayed.
This would make sense to you, if you wish to simply set the tics after the value of 2 like
set xtics 2, 1
The other thing you can do, is add explicit tic labels to certain values like
set xtics add ("0.1" 0, "0.4" 1)
This would introduce the labels 0.1, and 0.4 to the x scale where the actual values are 0 and 1
However you cannot modify the actual plotting of the graph. If in you data it states
0.1 100
0.4 150
1 200
2 300
then gunplot will plot it correspondingly.
Possible workaround
A workaround could look like this:
Plot the normal graph from 2 upwards.
Do some hackery stuff to the first two values with this:
plot "Data.dat" every 1::2 w l, "" every 1::1::2 using ($1<magic>):($2)
magic specifies some algebraic operation you want to do with the first column.
Everything is allowed and if your values are constant you can specify a polynomial that goes through the points 0, 1 and 2 with the inputs 0.1, 0.4 and 1 like this polynomial:
y = -1.85*x^2 + 4.26*x - 1.4
Example
Suppose you have this data file:
0.1 0.41
0.4 0.03
1 0.97
2 0.74
3 0.05
4 0.15
5 0.11
6 0.60
7 0.76
8 0.25
Then you can "rearrange" the first two entries to the x-positions -1 and 0 like this:
plot "Data.dat" every 1::2 w l, \
"" every 1::0::2 using (-1.85*$1**2 + 4.26*$1 - 1.4):($2) w l
With some tic-labeling and line style settings it should look exactly like what you are after.
I hope I understood what you are after and that you can make some use of my suggestions.
Cherio
Woltan