2

I am using the new feature introduced in Gnuplot 5.0 to create a datablock and plot it using the following code.

#set term wxt enhanced 0 font 'Helvetica,' noraise

# set labels
set title 'Sample Points'
set xlabel 'X pos' offset -5
set ylabel 'Y pos' offset 3
set zlabel 'Speed' offset -2 rotate left
set key outside right top box

set grid
set border 4095
set xtics 20
set ytics 20

set style line 1 pointtype 7 pointsize 1 lc rgb 'red'
set style line 2 pointtype 7 pointsize 1 lc rgb 'green'
set style line 3 pointtype 7 pointsize 1 lc rgb 'blue'

# loop begin

$data << EOD 
821.328349 898.350000 18.887529 0 
901.650000 821.328349 18.887529 1 
898.350000 978.671651 18.887529 2 
978.671651 901.650000 18.887529 3 
823.181732 898.350000 18.533830 0 
901.650000 823.181732 18.533830 1 
898.350000 976.818268 18.533830 2 
976.818268 901.650000 18.533830 3 
824.999809 898.350000 18.180776 0 
901.650000 824.999809 18.180776 1 
898.350000 975.000191 18.180776 2 
975.000191 901.650000 18.180776 3 
826.782868 898.350000 17.830582 0 
901.650000 826.782868 17.830582 1 
898.350000 973.217132 17.830582 2 
973.217132 901.650000 17.830582 3 
828.531204 898.350000 17.483360 0 
901.650000 828.531204 17.483360 1 
898.350000 971.468796 17.483360 2 
971.468796 901.650000 17.483360 3 


830.244850 898.350000 17.136468 0 
901.650000 830.244850 17.136468 1 
898.350000 969.755150 17.136468 2 
969.755150 901.650000 17.136468 3 
831.924084 898.350000 16.792338 0 
901.650000 831.924084 16.792338 1 
898.350000 968.075916 16.792338 2 
968.075916 901.650000 16.792338 3 
833.569227 898.350000 16.451429 0 
901.650000 833.569227 16.451429 1 
898.350000 966.430773 16.451429 2 
966.430773 901.650000 16.451429 3 
835.180379 898.350000 16.111523 0 
901.650000 835.180379 16.111523 1 
898.350000 964.819621 16.111523 2 
964.819621 901.650000 16.111523 3 
836.757776 898.350000 15.773971 0 
901.650000 836.757776 15.773971 1 
898.350000 963.242224 15.773971 2 
963.242224 901.650000 15.773971 3 


838.301768 898.350000 15.439919 0 
901.650000 838.301768 15.439919 1 
898.350000 961.698232 15.439919 2 
961.698232 901.650000 15.439919 3 
839.812485 898.350000 15.107162 0 
901.650000 839.812485 15.107162 1 
898.350000 960.187515 15.107162 2 
960.187515 901.650000 15.107162 3 
841.290161 898.350000 14.776766 0 
901.650000 841.290161 14.776766 1 
898.350000 958.709839 14.776766 2 
958.709839 901.650000 14.776766 3 
842.735180 898.350000 14.450189 0 
901.650000 842.735180 14.450189 1 
898.350000 957.264820 14.450189 2 
957.264820 901.650000 14.450189 3 
844.147653 898.350000 14.124734 0 
901.650000 844.147653 14.124734 1 
898.350000 955.852347 14.124734 2 
955.852347 901.650000 14.124734 3 


845.527869 898.350000 13.802154 0 
901.650000 845.527869 13.802154 1 
898.350000 954.472131 13.802154 2 
954.472131 901.650000 13.802154 3 
846.876245 898.350000 13.483757 0 
901.650000 846.876245 13.483757 1 
898.350000 953.123755 13.483757 2 
953.123755 901.650000 13.483757 3 
848.192819 898.350000 13.165744 0 
901.650000 848.192819 13.165744 1 
898.350000 951.807181 13.165744 2 
951.807181 901.650000 13.165744 3 
849.477992 898.350000 12.851735 0 
901.650000 849.477992 12.851735 1 
898.350000 950.522008 12.851735 2 
950.522008 901.650000 12.851735 3 
850.732123 898.350000 12.541306 0 
901.650000 850.732123 12.541306 1 
898.350000 949.267877 12.541306 2 
949.267877 901.650000 12.541306 3 


851.955313 898.350000 12.231900 0 
901.650000 851.955313 12.231900 1 
898.350000 948.044687 12.231900 2 
948.044687 901.650000 12.231900 3 
853.148046 898.350000 11.927332 0 
901.650000 853.148046 11.927332 1 
898.350000 946.851954 11.927332 2 
946.851954 901.650000 11.927332 3 
854.310507 898.350000 11.624608 0 
901.650000 854.310507 11.624608 1 
898.350000 945.689493 11.624608 2 
945.689493 901.650000 11.624608 3 
855.443020 898.350000 11.325128 0 
901.650000 855.443020 11.325128 1 
898.350000 944.556980 11.325128 2 
944.556980 901.650000 11.325128 3 
856.546040 898.350000 11.030203 0 
901.650000 856.546040 11.030203 1 
898.350000 943.453960 11.030203 2 
943.453960 901.650000 11.030203 3 


857.619649 898.350000 10.736086 0 
901.650000 857.619649 10.736086 1 
898.350000 942.380351 10.736086 2 
942.380351 901.650000 10.736086 3 
858.664411 898.350000 10.447624 0 
901.650000 858.664411 10.447624 1 
898.350000 941.335589 10.447624 2 
941.335589 901.650000 10.447624 3 
859.680471 898.350000 10.160601 0 
901.650000 859.680471 10.160601 1 
898.350000 940.319529 10.160601 2 
940.319529 901.650000 10.160601 3 
860.668283 898.350000 9.878115 0 
901.650000 860.668283 9.878115 1 
898.350000 939.331717 9.878115 2 
939.331717 901.650000 9.878115 3 
861.628190 898.350000 9.599073 0 
901.650000 861.628190 9.599073 1 
898.350000 938.371810 9.599073 2 
938.371810 901.650000 9.599073 3 


862.560481 898.350000 9.322910 0 
901.650000 862.560481 9.322910 1 
898.350000 937.439519 9.322910 2 
937.439519 901.650000 9.322910 3 
863.465671 898.350000 9.051895 0 
901.650000 863.465671 9.051895 1 
898.350000 936.534329 9.051895 2 
936.534329 901.650000 9.051895 3 
864.343914 898.350000 8.782434 0 
901.650000 864.343914 8.782434 1 
898.350000 935.656086 8.782434 2 
935.656086 901.650000 8.782434 3 
865.195863 898.350000 8.519487 0 
901.650000 865.195863 8.519487 1 
898.350000 934.804137 8.519487 2 
934.804137 901.650000 8.519487 3 
866.021577 898.350000 8.257141 0 
901.650000 866.021577 8.257141 1 
898.350000 933.978423 8.257141 2 
933.978423 901.650000 8.257141 3 


866.821806 898.350000 8.002291 0 
901.650000 866.821806 8.002291 1 
898.350000 933.178194 8.002291 2 
933.178194 901.650000 8.002291 3 
867.596557 898.350000 7.747514 0 
901.650000 867.596557 7.747514 1 
898.350000 932.403443 7.747514 2 
932.403443 901.650000 7.747514 3 
868.346635 898.350000 7.500778 0 
901.650000 868.346635 7.500778 1 
898.350000 931.653365 7.500778 2 
931.653365 901.650000 7.500778 3 
869.072042 898.350000 7.254067 0 
901.650000 869.072042 7.254067 1 
898.350000 930.927958 7.254067 2 
930.927958 901.650000 7.254067 3 
869.773586 898.350000 7.015447 0 
901.650000 869.773586 7.015447 1 
898.350000 930.226414 7.015447 2 
930.226414 901.650000 7.015447 3 
EOD

splot '$data' index 0 using 1:2:3 with points ls 1 title 'class 1',\
      ''      index 1 using 1:2:3 with points ls 2 title 'class 2',\
      ''      index 2 using 1:2:3 with points ls 3 title 'class 3',\
      ''      index 3 using 1:2:3 with points ls 1 title 'class 4',\
      ''      index 4 using 1:2:3 with points ls 2 title 'class 5',\
      ''      index 5 using 1:2:3 with points ls 3 title 'class 6',\
      ''      index 6 using 1:2:3 with points ls 1 title 'class 7',\
      ''      index 7 using 1:2:3 with points ls 2 title 'class 8'

# loop end

The whole datablock section and splot command are in a loop. Every time that I get a new point, I make a new datablock and then splot it. This approach is inefficient and I am looking for a way to only append the new point to the existing data without the need to re-construct the whole datablock in the script. How can I achieve that?

Edit: I don't want to use an external file.

1 Answer 1

3

You can print to a datablock, both overwriting or appending it. Suppose that I use

$k << EOD
1 2
2 3
4 5
EOD

To create datablock $k. Now I wish to add a new line 5 6 to this. I first set the print output to the datablock, and then print my new line, setting the print command back when I am done.

set print $k append
print "5 6"
set print

Now my datablock $k looks like

1 2
2 3
4 5
5 6

I can even create multiple blocks by printing blank lines. For example, if I wish to use my existing $k to create a new $l with two blocks (no append, as I don't need to append to an existing block), I can do

set print $l
print $k
print ""
print $k
set print

This sets up a new block $l with

1 2
2 3
4 5
5 6


1 2
2 3
4 5
5 6

Unfortunately, this will insert a blank line after each copy of $k (as the print command adds a newline deliminator, and the block already has one), so this won't work if you need to keep repeating the same base and add a few extra lines to each block. Storing the data in a string can allow that.

bse = "1 2\n2 3\n4 5"
set print $l
print bse
print "5 6"
print ""
print ""
print bse
print "7 8"
set print

This will produce

1 2
2 3
4 5
5 6


1 2
2 3
4 5
7 8
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.