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

Re: gnuplot: plotting each point in different color



On Thu, Mar 27, 2008 at 18:45:21 -0400, H.S. wrote:
> Florian Kulzer wrote:

[...]

>> 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.

Yes, maybe.

> 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?

Yes, it does, but the number of easily distinguishable colors is
limited, too. With the above approach you can at least vary the point or
line style if you have to use similar colors for more than one subset of
the data.

> 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.  

I am not sure if this is easily possible or if it makes sense (see
above). I tend not to spend time wrestling with gnuplot's style and
color defaults, I simply produce an EPS output file with the default
settings and then I modify the EPS file directly. Colors and line/point
styles in gnuplot's EPS files can easily be changed by simple sed
operations (which can be embedded as external commands in the gnuplot
script).

> plotting, I would need to increase that number somehow, if possible. As  
> you correctly mentioned, this approach is fine for small number of 
> colors.

One more thing worth mentioning is that the subroutine trick can also be
used to loop over the columns of a dataset (using the "column" command),
for example if you have a data file with one common x-axis and 100
y-datasets (columns) that you want plot in the same graph. (Or can the
plot command do this automatically these days?)

-- 
Regards,            | http://users.icfo.es/Florian.Kulzer
          Florian   |


Reply to: