PM3d and Impulses combined not scaling - gnuplot

I am new to gnuplot, but I think I have all the basics. I am trying to plot a 3d surface with some impulses. When I do each splot individually, they look great, but when I splot them together, the scale gets all messed up. Any thoughts? Autoscale is set in all cases.
1st splot:
splot "C:/data/file1.dat" matrix rowheaders columnheaders with pm3d
2nd splot:
splot "C:/Data/file2.dat" with impulses, "C:/Data/file2.dat" with points pt 7
Combined:
splot "C:/data/file1.dat" matrix rowheaders columnheaders with pm3d, \
"C:/Data/file2.dat" with impulses, \
"C:/Data/file2.dat" with points pt 7
See how the scale gets all messed up, and the first chart gets scrunched down to one corner? Both data sets have roughly the same ranges in data.
file1.dat
6 8 10 12 16 20 24
30 3.513999939 4.515999794 5.293000221 5.894999981 6.633999825 6.870999813 6.901000023
35 4.235000134 5.330999851 6.169000149 6.72300005 7.196000099 7.374000072 7.434000015
40 4.818999767 5.940999985 6.776000023 7.171000004 7.558000088 7.722000122 7.802999973
45 5.291999817 6.453999996 7.136000156 7.480999947 7.831999779 7.997000217 8.092000008
50 5.656000137 6.791999817 7.393000126 7.718999863 8.057999611 8.232999802 8.340000153
55 5.968999863 7.014999866 7.587999821 7.913000107 8.255000114 8.44299984 8.565999985
60 6.225999832 7.176000118 7.741000175 8.079999924 8.434000015 8.642000198 8.788000107
65 6.414000034 7.326000214 7.859000206 8.225999832 8.602000237 8.840000153 9.015000343
70 6.624000072 7.494999886 7.956999779 8.357000351 8.767000198 9.039999962 9.25
75 6.801000118 7.638999939 8.100999832 8.468000412 8.930000305 9.251999855 9.496999741
80 6.93599987 7.758999825 8.222000122 8.56799984 9.107999802 9.491000175 9.772000313
85 7.035999775 7.855000019 8.322999954 8.690999985 9.289999962 9.748999596 10.10700035
90 7.102000237 7.919000149 8.409999847 8.80300045 9.470999718 10.03199959 10.47500038
95 7.125 7.933000088 8.479000092 8.901000023 9.642999649 10.31599998 10.83600044
100 7.107999802 7.907999992 8.534000397 8.987000465 9.812000275 10.60000038 11.18799973
105 7.053999901 7.849999905 8.515999794 9.06000042 9.972999573 10.86600018 11.52400017
110 6.965000153 7.769999981 8.43500042 9.090999603 10.11800003 11.10400009 11.84200001
115 6.840000153 7.663000107 8.309000015 8.961000443 10.24100018 11.31099987 12.14299965
120 6.672999859 7.524000168 8.149999619 8.75399971 10.32299995 11.48900032 12.42500019
125 6.436999798 7.349999905 7.961999893 8.529000282 9.987000465 11.64599991 12.68999958
130 6.044000149 7.133999825 7.749000072 8.298000336 9.579000473 11.67500019 12.96199989
135 5.572000027 6.856999874 7.513000011 8.06499958 9.237999916 11.11900043 13.27099991
140 5.127999783 6.440000057 7.257999897 7.831999779 8.937999725 10.52499962 12.90999985
145 4.683000088 5.933000088 6.981999874 7.598999977 8.670000076 10.0170002 12.10299969
150 4.30700016 5.52699995 6.657999992 7.363999844 8.425999641 9.602999687 11.39599991
155 3.996999979 5.196000099 6.294000149 7.122000217 8.194000244 9.262000084 10.79100037
160 3.730999947 4.887000084 5.936999798 6.868999958 7.973999977 8.970999718 10.27600002
165 3.506999969 4.620999813 5.642000198 6.610000134 7.78000021 8.737999916 9.892000198
170 3.342999935 4.421999931 5.427999973 6.385000229 7.625 8.56499958 9.626999855
175 3.233999968 4.288000107 5.281000137 6.217000008 7.506999969 8.43900013 9.44299984
180 3.170000076 4.209000111 5.191999912 6.111000061 7.428999901 8.354000092 9.32199955
file2.dat
7.5 172.0 4.5
5.6 56.8 4.7
6.7 35.0 5.1
11.0 158.7 5.3
13.8 24.8 5.6
12.1 180.0 6.0
5.1 83.2 6.4
13.2 158.0 6.6
15.8 34.5 6.67
15.6 32.9 6.69
11.8 180.0 6.8
13.7 96.0 7.2
15.0 62.4 7.3
11.2 76.2 7.3
11.7 84.9 7.4
13.8 121.8 7.46
9.7 90.9 7.6
13.2 66.0 7.64
14.3 61.3 7.8
14.8 124.6 8.0
9.5 118.8 8.20
15.1 148.8 8.29
12.2 81.8 8.4

You can see in your first image that the spacing between x=10 and x=12 is as big as the spacing between x=12 and x=16, which gives a clue to what's going on: while first plot looks like gnuplot is using the x coordinates 8,10,12,16,20,24, those are really only labels, while numerically gnuplot uses the x coordinates 0,1,2,3,4,5,6. So when you then plot the second graph on the same scale, the data points have x values between 5.1 and 15.8, so will show up the side of the pm3d surface.
If you want gnuplot to use the first column and first row as actual coordinates, you have to use the nonuniform matrix format (see help matrix nonuniform). First, you need to change your data file file1.dat to start with the number 7, the number of columns. The beginning of the file should look like this:
7 6 8 10 12 16 20 24
30 3.513999939 4.515999794 5.293000221 5.894999981 6.633999825 6.870999813 6.901000023
35 4.235000134 5.330999851 6.169000149 6.72300005 7.196000099 7.374000072 7.434000015
Then you can plot the data as follows:
splot "file1.dat" nonuniform matrix w pm3d, \
"file2.dat" with impulses, \
"file2.dat" with points pt 7

Related

How to plot points with label and color in Gnuplot?

I want to plot points with individual labels and colors in Gnuplot.
I have a data file a.dat:
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
The following commands work.
splot 'a.dat' using 2:3:4:1 with labels
set palette model RGB defined (0 'black',1 'blue', 2 'green', 3 'red')
splot 'a.dat' using 2:3:4:($1==3?1:$1==6?2:$1==9?3:0) with points palette
But how can I mix them?
Assuming I understood your question correctly, do you really need a palette if you just want to set only a few specific colors to a few specific points?
You are using two plotting styles with points and with labels you can combine them in one plot command.
Code:
### variable color points
reset session
$Data <<EOD
###label x y z
1 244.8 18 6.1
2 248.0 10.4 7
3 294.4 6.3 13.7
4 248.0 7.5 8.92
5 240.0 3.69 6.61
6 240.48 3.69 8.92
7 256 5.7 15.8
8 256 7 10.6
9 256 4.1 8.2
10 256 5.1 12.3
EOD
myColor(col) = column(col)==3 ? 0x0000ff : \
column(col)==6 ? 0x00ff00 : \
column(col)==9 ? 0xff0000 : 0
set key noautotitle
splot $Data u 2:3:4:(myColor(1)) w p pt 7 lc rgb var, \
'' u 2:3:4:1 w labels offset 0.0,0.7,0.7
### end of code
Result:
Addition: (colored labels)
If you want to have colored labels then change the plot command as follows:
splot $Data u 2:3:4:1:(myColor(1)) w labels tc rgb var
Well, you have to decide:
using only labels it might be difficult to locate the exact position of your data point
using a point and a label without offset it might be diffcult to read the number
Result: (colored label without point)

Gnuplot - How to join smoothly ordered points?

I've a set of data in three columns:
1st column: order criterion between 0 and 1
2nd: x vals
3rd: y vals
As a data file example:
0.027 -29.3 -29.6
0.071 -26.0 -31.0
0.202 -14.0 -32.8
0.304 -3.4 -29.3
0.329 -0.5 -26.0
0.409 6.7 -14.0
0.458 11.7 -3.4
0.471 12.8 -0.5
0.495 12.5 6.7
0.588 18.8 11.7
0.600 20.4 12.8
0.618 20.8 12.5
0.674 20.9 18.8
0.754 22.1 20.4
0.810 27.0 20.8
0.874 24.7 20.9
0.892 9.4 22.1
0.911 -11.5 27.0
0.943 -23.7 24.7
0.962 -29.6 9.4
0.991 -31.0 -11.5
0.999 -32.8 -23.7
My goal is to plot (x,y) points and a trend curve passing through each points ordered in ascending order with the first column values.
I use the following script:
set terminal png small size 600,450
set output "my_data_mcsplines_joined_points.png"
set table "table_interpolation.dat"
plot 'my_data.dat' using 2:3 smooth mcsplines
unset table
plot 'my_data.dat' using 2:3:(sprintf("%'.3f", $1)) with labels point pt 7 offset char 1,1 notitle ,\
"table_interpolation.dat" with lines notitle
Here mcspline results as an example:
mcspline joined points figure
The resulting curve should have the shape of a spindle or a loop.
Whatever smooth options used, Gnuplot seems invalid to handle such aim.
Unfortunatly most of smooth (mcspline, csplines...) options do a monotonic ordering of data.
How can I plot a trend curve passing through each points ordered in ascending order with the first column values?
Thanks.
I cannot post an image in a comment, and so place it here. I don't think a 2D plot will be sufficient, based on this 3D acatterplot of the data in your question.

Difficulties creating a scatter graph in Excel

I have 4 columns of data to display in a scatter graph in excel
Trade Name
Amatib
AMOXICI
Amoxinsol
Amoxival
Amoxy Activ
Bioamoxi
Biocillin
Citramox
CITRAMOX 50
MAXYL
Octacillin
Rhemox
SOLAMOCTA 
Trioxyl500
Irl DDD
16
15
15
20
20
20
15
15
15
15
12
15
13.1
15
AVE Irl
15.8
15.8
15.8
15.8
15.8
15.8
15.8
15.8
15.8
15.8
15.8
15.8
15.8
15.8
EU DDD
16
16
16
16
16
16
16
16
16
16
16
16
16
16
I want the y axis to be a list of the names in a row and the x axis to go somewhere from 10 to 22 with each number a non connected point, or just the first two rows of data and then I can add in a straight line for the 15.8 and 16. I can't figure out how to do it!
Thanks
lbr, you will have to use a Line Chart and then make it look like a scatter. Scatter seems to only accept numeric x and y axis values.
Here I selected my Trade Name and irlDD data in columns and went Insert Line Chart. Then I set:
Line - No Line
Marker Options - built in
Let me know if you need more help with this. To set the axis to 10 to 22 then you will just format the y axis (double click on axis, set the minimum bound to 10 for example).

Grouping Data Sets Together + Legend

I'm unfamiliar with the terminology of what I'm trying to do (which is making it difficult to find the solution), but I think you can figure out what I'm trying to do from the inputfile. Input file is .txt that is tab separated.
#input file begins here
21 00 0.005 12.0 0.006621 0.35365 0.16718
22 00 0.005 14.0 0.00662 0.34899 0.17206
23 00 0.005 16.0 0.006645 0.34523 0.17739
24 00 0.005 18.0 0.006696 0.33956 0.1815
25 00 0.005 20.0 0.006755 0.33477 0.18692
26 00 0.005 22.0 0.006797 0.33084 0.19178
27 00 0.005 24.0 0.006892 0.3265 0.19683
28 00 0.005 26.0 0.006965 0.32093 0.20256
29 00 0.005 28.0 0.007072 0.31631 0.20747
31 00 0.007 12.0 0.006158 0.38969 0.12999
32 00 0.007 14.0 0.006124 0.38578 0.13541
33 00 0.007 16.0 0.006136 0.38161 0.14018
34 00 0.007 18.0 0.006147 0.37697 0.1452
35 00 0.007 20.0 0.006193 0.37356 0.14999
36 00 0.007 22.0 0.006238 0.3673 0.15499
37 00 0.007 24.0 0.006276 0.36387 0.16037
38 00 0.007 26.0 0.00634 0.35855 0.16595
39 00 0.007 28.0 0.006417 0.35388 0.17118
40 00 0.007 30.0 0.006497 0.34844 0.17673
I would like to differentiate between these two blocks of data on the graph. The graph will be a 2D plot, with the top block's points in red and the bottom block's points in blue. The total inputfile is about 1000 lines long, with different vertical lengths; however, they are all appropriately separated with the newline character (\n).
I'm plotting columns 4 and 6 with the data set name (a.k.a. legend label) being column 3.
Here is how you can address the different points:
Your input file indeed consists of two data blocks, which can be selected with every for plotting: every :::0::0 selects only the first block, see the documentation or help every.
To use a red line color, just use e.g.
plot 'file.txt' linecolor rgb 'red'
To select columns 4 and 6 for plotting, use using 4:6.
Using the values of the third columns as key labels is not straightforward. If you know that it is a numerical value, than you can use the stats command to extract these single values (see e.g. Gnuplot: How to load and display single numeric value from data file):
stats 'file.txt' using 3 every :::0::0 nooutput
key1 = sprintf('%.3f', STATS_max)
stats 'file.txt' using 3 every :::1::1 nooutput
key2 = sprintf('%.3f', STATS_max)
If the column can also contain other values, or you want to maintain this same formatting, you need an external tool to extract the values for the title:
key1 = system('head -1 file.txt | cut -f 3')
key2 = system('tail -1 file.txt | cut -f 3')
So, alltoghether you script may look like the following:
stats 'file.txt' using 3 every :::0::0 nooutput
key1 = sprintf('%.3f', STATS_max)
stats 'file.txt' using 3 every :::1::1 nooutput
key2 = sprintf('%.3f', STATS_max)
plot 'file.txt' using 4:6 every :::0::0 linecolor rgb 'red' title key1,\
'' using 4:6 every :::1::1 linecolor rgb 'blue' title key2

Labelling individual data points gnuplot

Just trying to get used to gnuplot. I searched a few pages on this site looking for the answer, read the documentation (4.6), and still haven't found the answer. say I have a data file like this:
0.0 0
1.0 25
2.0 55
3.0 110
4.0 456
5.0 554
6.0 345
and I want to label all the data points on the plot. How do I do this? I tried this suggestion plot 'exp.dat' u 1:2 w labels point offset character 0,character 1 tc rgb "blue" but it didn't work. It gave me a Not enough columns for this style response. I'm sure it's something I'm doing but I'm not sure what. Any help would be appreciated. Thanks.
I think you are missing strings for labels. You can do
flabel(y)=sprintf("y=%.2f", y)
plot '-' u 1:2:(flabel($2)) w labels point offset character 0,character 1 tc rgb "blue"
0.0 0
1.0 25
2.0 55
3.0 110
4.0 456
5.0 554
6.0 345

Resources