Matlab, Python: Fixing colormap to specified values
It is a simple but common task required when trying to fix a colormap according to a 2D matrix of values.
To demonstrate consider the problem in **Matlab**, the solution does not need to be in **Matlab** (i.e., the code presented here is only for demonstration purpose).  
<pre><code>
x = [0,1,2; 3,4,5; 6,7,8];
imagesc(x)
axis square
axis off
</pre></code>
So the output is as:  
![enter image description here][1]  
when some values change to over the maximum value it happens like:  
<pre><code>
x = [0,1,2; 3,4,5; 6,7,18];
</pre></code>
which looks logical but makes problems when we wish to compare/trace elements in two maps. Since the colormap association is changed it is almost impossible to find an individual cell for comparison/trace etc.
![enter image description here][2]  
The solution I implemented is to mask the matrix as:
<pre><code>
x = [0,1,2; 3,4,5; 6,7,18];
m = 8;
x(x>=m) = m;
</pre></code>
which works perfectly.  
Since the provided code requires searching/filtering (extra time consuming!) I wonder if there is **a general/more efficient way** for this job to be implemented in **Matlab**, **Python** etc?

One of the cases that this issue occurs is when we have many simulations sequentially and wish to make a sense-making animation of the progress; in this case each color should keep its association fixed.


  [1]: http://i.stack.imgur.com/96dhI.png
  [2]: http://i.stack.imgur.com/FajA0.png
Matlab, Python: Fixing colormap to specified values
===

It is a simple but common task required when trying to fix a colormap according to a 2D matrix of values.
To demonstrate consider the problem in **Matlab**, the solution does not need to be in **Matlab** (i.e., the code presented here is only for demonstration purpose).  
<pre><code>
x = [0,1,2; 3,4,5; 6,7,8];
imagesc(x)
axis square
axis off
</pre></code>
So the output is as:  
![enter image description here][1]  
when some values change to over the maximum value it happens like:  
<pre><code>
x = [0,1,2; 3,4,5; 6,7,18];
</pre></code>
which looks logical but makes problems when we wish to compare/trace elements in two maps. Since the colormap association is changed it is almost impossible to find an individual cell for comparison/trace etc.
![enter image description here][2]  
The solution I implemented is to mask the matrix as:
<pre><code>
x = [0,1,2; 3,4,5; 6,7,18];
m = 8;
x(x>=m) = m;
</pre></code>
which works perfectly.  
Since the provided code requires searching/filtering (extra time consuming!) I wonder if there is **a general/more efficient way** for this job to be implemented in **Matlab**, **Python** etc?

One of the cases that this issue occurs is when we have many simulations sequentially and wish to make a sense-making animation of the progress; in this case each color should keep its association fixed.


  [1]: http://i.stack.imgur.com/96dhI.png
  [2]: http://i.stack.imgur.com/FajA0.png