help-octave
[Top][All Lists]
Advanced

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

Coloring grid spaces in a 2D by index


From: BGreen
Subject: Coloring grid spaces in a 2D by index
Date: Tue, 2 Jul 2019 12:48:33 -0500 (CDT)

I would like to have a grid in which each box is filled with a color
corresponding to a value. What is the best way to do this?

Below is an example of what I've produced so far, which is okay but not
quite what I want.

<http://octave.1599824.n4.nabble.com/file/t373379/Example.png> 

minindex is the matrix of values I wish to color by number, and the x and y
axes are Bvec and Dbiasvec. I have used the following code and it works, but
it's not the ideal solution.

        mksz = 10;
        clf
        hold on
        for m=1:length(Bvec)
                for j=1:length(Dbiasvec)
                        if minindex(m,j)==3 % FOP
                                clr = "green";
                        
plot(Bvec(m),Dbiasvec(j),"color",clr,"marker","s","markerfacecolor",clr,"markersize",mksz)
                        elseif minindex(m,j)==4 % POP
                                clr = [1,0.5,0];
                        
plot(Bvec(m),Dbiasvec(j),"color",clr,"marker","s","markerfacecolor",clr,"markersize",mksz)
                        elseif minindex(m,j)==2 % FVP
                                clr = "red";
                        
plot(Bvec(m),Dbiasvec(j),"color",clr,"marker","s","markerfacecolor",clr,"markersize",mksz)
                        elseif minindex(m,j)==1 % FSP
                                clr = "blue";
                        
plot(Bvec(m),Dbiasvec(j),"color",clr,"marker","s","markerfacecolor",clr,"markersize",mksz)
                        elseif minindex(m,j)==5 % FSP-FVP
                                clr = "black";
                        
plot(Bvec(m),Dbiasvec(j),"color",clr,"marker","s","markerfacecolor",clr,"markersize",mksz)
                        else % OSP-POP
                                clr = [0.75,0,0.75];
                        
plot(Bvec(m),Dbiasvec(j),"color",clr,"marker","s","markerfacecolor",clr,"markersize",mksz)
                        end
                end
        end

With this approach the colored boxes are centered on the corresponding
values, just as I would like, but there are unsightly gaps in between.

pcolor has the plus of no gaps, but as far as I know I can't just specify a
custom color corresponding to each discrete value.

Is there better way to do generate the sort of plot I would like?



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]