help-octave
[Top][All Lists]
Advanced

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

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 16:49:45 -0400

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



reply via email to

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