help-octave
[Top][All Lists]

## Re: Coloring grid spaces in a 2D by index

 From: Brett Green Subject: Re: Coloring grid spaces in a 2D by index Date: Wed, 3 Jul 2019 19:18:03 -0400

The axes is present but hidden, so you can use "axis on" to see it.

Pantxo

PS: It is good practice in this mailing list to bottom post, i.e. answer bellow the post you are citing.

Thank you very much for both the plotting help and the etiquette pointer!

I read your solution and realized that this is something I had thought of earlier (since the same method can be applied to surf and pcolor) but hadn't done because there is one more problem - I actually want two sections with two different continuous color transitions. The problem here is that if I do something like

colormap([ redblue ; 0, 1, 0 ; 1, 0.5, 0 ; orangepurple ]

and have a continuum of numbers from 1 to 2 for redblue, then 3 and 4 discrete for the middle two, and finally a continuum 5 to 6 for orangepurple, then Octave will decide where it wants to draw the line in the colormap as to what number receives which color. For example, 3 and 4 could end up as part of the redblue spectrum, so that everything from 1 to 4 is some shade of red or blue, and then 5 and greater would be in the orangepurple part of the colormap.

Is there a way to fix specific values to specific colors?

- Brett Green

On Wed, Jul 3, 2019 at 5:18 PM Pantxo Diribarne <address@hidden> wrote:
Le 03/07/2019 à 22:49, Brett Green a écrit :
Thank you for pointing that out! That looks nice. Is there a way to do it with axes? imshow doesn't produce axes for me, but I need those.

- Brett Green

On Wed, Jul 3, 2019 at 4:43 PM Pantxo <address@hidden> wrote:
BGreen wrote
> To superimpose plots with different colormaps, I have to plot them to
> separate axes and then assign different colormaps to the separate axes.
> However, the axes have an opaque background. I just checked the
> documentation for axes(), and although there are properties for
> transparency, they're currently unused because that functionality has not
> been implemented yet. I guess that means I need to find another way.
>
> For completeness, here's the code that overlays two axes objects with
> different colormaps, but will not work for my purposes because they're
> opaque.
>
> blue = [0,0,1];
> red = [1,0,0];
> green = [0,1,0];
> orange = [1,0.5,0];
> purple = [0.75,0,0.75];
>
> discrete_clrmp = [blue;red;green;orange];
>
> redblue_clrmp =
> [linspace(0,1,100)',zeros(100,1),fliplr(linspace(0,1,100))'];
> orangepurple_clrmp =
> [fliplr(linspace(0,1,100))',fliplr(linspace(0,0.5,100))',linspace(0,0.75,100)'];
>
> fig = figure(3);
> ax1 = axes(fig);
> colormap(ax1,discrete_clrmp);
> ax2 = axes(fig);
> colormap(ax2,redblue_clrmp);
>
> data = ""> > pcolor(ax1,data);
> view(2)
> continuousdata = rand(23);
> pcolor(ax2,continuousdata)
> view(2)

IIUC you have data points in the range [1 2] and for some reason some of
them
are tagged 3 or 4:

## The original data
data = "" (100) + 1;
data(rand(100) < 0.1) = 3;
data(rand(100) < 0.1) = 4;

## The colormap you want
nlev = 50;
redblue = [linspace(0,1,nlev)',zeros(nlev,1),fliplr(linspace(0,1,nlev))'];
cmap = [redblue; 0 1 0; 1 0.5 0];

## Now manipulate the data for plotting
data(data == 3) = nlev + 1;
data(data == 4) = nlev + 2;
data(data<3) = (data(data<3) - 1) * (nlev-1) + 1;
imshow (data, cmap, "xdata", (-10:10), "ydata", (-10:10))

HTH,

Pantxo

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

The axes is present but hidden, so you can use "axis on" to see it.

Pantxo

PS: It is good practice in this mailing list to bottom post, i.e. answer bellow the post you are citing.