[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: gnuplot: plotting each point in different color



Florian Kulzer wrote:


The gnuplot list is no match for the vast and mysterious powers of
debian-user...

How true! This is actually a very insightful observation. I have at times wondered why that list or newsgroup is so low traffic. Perhaps it is due to lack of helpful people over there. Additionally, the list is inundated with spam. It looks like an abandoned list, as if users just don't find it useful any more.


So, can anyone here give an example using the plot command for this purpose? This is on Debian testing, Gnuplot 4.2.

For a small number of colors something like this is may be acceptable:

# START
unset key
set xrange [0:1]
set yrange [0:1]
set multiplot
plot "3cols.dat" using ($1):($3==1 ? $2 : 1/0) lt 1
plot "3cols.dat" using ($1):($3==2 ? $2 : 1/0) lt 2
plot "3cols.dat" using ($1):($3==3 ? $2 : 1/0) lt 3
plot "3cols.dat" using ($1):($3==4 ? $2 : 1/0) lt 4
unset multiplot
# END

To scale this up sensibly for many more colors, put the plot command
into a separate file that is called as a subroutine from the main
program. In this subroutine you can use a counter variable for both the
$3 comparison and the lt assignment. After the plot command you can
increment the counter and use the if/reread trick (see the manual) to
make sure that the subroutine is re-executed as many times as is
necessary to loop over all the colors.


Please see my earlier post. Using splot may be a better solution since I did not have to do any comparisons there. But your example is very interesting and lists some neat tricks, and it uses the 'plot' instead of 'splot'. However, I have a little doubt. You are differentiating the plotted points with the linetype, "lt", right? Doesn't lt cycle back in gnuplot after a certain number of plots? I guess how many such types are available can be determined using the 'test' command in gnuplot. Before plotting, I would need to increase that number somehow, if possible. As you correctly mentioned, this approach is fine for small number of colors.

thanks and regards,
->HS




Reply to: