0

I'm attempting to make a 2D scatterplot using advice that I received Cannot get labels to color in GNUPlot

which led me to write:

$DATA << EOD
3.12960004005165    2.67469663590573    0.438527882947657
3.54159282682062    1.48608712150729    3.45059090334765
1.41832139944261    1.09739773669576    4.7851179962913
0.37050714994141    4.51679511956513    2.99273024822522
1.33417336450785    2.60931115605578    3.49852244355505
4.68608825227413    4.50263530942483    0.708639941290272
EOD
set datafile separator "\t"
set xlabel 'x'
set ylabel 'y'
set title 'title'
set terminal svg
set output 'scatterplotx_y.svg'
set key off
myColor(col) = int("0x".strcol(col)[3:])
plot $DATA using 1:2:(myColor(3)) pt 7

I'm using gnuplot 5.2 patchlevel 8

I've also tried

plot $DATA u 1:2:3 with lines palette

suggested by Line plot in GnuPlot where line color is a third column in my data file? but that doesn't work

plot $DATA u 1:2:3 with points color $3

I'm using a palette now:

set palette defined (0 "red", 0.3 "orange", 0.625 "green", 0.85 "blue", 1 "dark-violet")

My question:

How can I plot the color from red to violet as determined by a number in [0,1], here the 3rd column? where red would be 0 and 1 would be violet, with all of the colors of the rainbow in the middle?

1

2 Answers 2

1

You are missing a keyword in the plot command to tell the program what the third column is to be used for.

plot $DATA u 1:2:3 with lines linecolor palette

Otherwise the program ignores the extra column because it doesn't know whether it is a z coordinate, a point size, or various other possibilities.

Actually there are further choices within the linecolor palette option. It could be linecolor palette z or linecolor palette fraction or linecolor palette cb.

  • The default is the first one palette z. It autoscales the values to use the entire palette range for the data in this plot.
  • palette fraction means the 3rd column is a number between 0 and 1 that selects a color that far into the palette range.
  • palette cb means the value in the 3rd column refers to a separate color range controlled by set cbrange [min:max].
Sign up to request clarification or add additional context in comments.

Comments

0

A gradient of colors is called a palette in GNUPlot

set palette defined (0 "red", 0.3 "orange", 0.625 "green", 0.85 "blue", 1 "dark-violet")

$DATA << EOD
4.47576802144342    3.96170057191894    0.965077628065902
0.476983571877412   3.8599136240968 4.12799054681166
4.87640196476667    4.52001611814199    3.14028639266551
2.261549757545  2.24147530185633    2.92342461107236
0.0119463593595448  3.63583286650188    1.78255268707661
3.4088757971039 2.11565314670896    1.62679271015364
EOD
set datafile separator "\t"
set xlabel 'x'
set ylabel 'y'
set title 'title'
set terminal svg
set output 'scatterplotx_y.svg'
set key off
plot $DATA u 1:2:3 with points palette

I don't know why, but plot $DATA u 1:2:3 with points palette somehow knows that the 3rd data point is the color.

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.