Using 2 color functions in a mathematica matrix plot

In summary, the individual color functions can be combined into one matrix plot by using a single color function that includes all the desired colors for the numbers in the matrix. The color function can be customized to vary from white to red for even numbers and from grey to black for odd numbers. The color function scaling can be suppressed in order to use the actual values of the matrix instead of a normalized scale. If a more normalized scale is desired, the min and max values of the matrix can be used in the color function.
  • #1
musicgirl
12
0
I'm trying to use 2 color functions within one matrix plot in mathematica. Is this possible to do?

For example, using a very simple matrix:

test = Partition[Table[i, {i, 1, 9}], 3]

I would like to make the even numbers vary in color increasing from white to red; and the odd numbers vary in color from grey to black.

How could I do this? I know how to get the whole matrix to vary in color, but no more than this.

Thanks
 
Physics news on Phys.org
  • #2
I think you would have much better luck making a single color function which includes each of the colors for 1...9
 
  • #3
Code:
test = Partition[Table[i, {i, 1, 9}], 3];
MatrixPlot[test, ColorFunction -> ((If[EvenQ[#1 ], RGBColor[1, 0, 0, #1/Max[test]], RGBColor[0, 0, 0, 1/4 + (3/4) #1/Max[test]]] &)), ColorFunctionScaling -> False]

Something like that?
Basically I suppress the color function scaling so instead of 0..1 they go from min..max. (so in this case, 1..9).

Then I let the color function be a function that is an If EVEN statement.

If the element #1 is even, then use RGBColor[1,0,0,A] (100 = red, A = alpha transparency, let it scale by the normalized value of the index (using #1/max). Similar for grey.

Now if you want to make it "more" normalized, then you need the min and max of test, and do something like :(#1 - Min[test])/Max[test]
So if your matrix was all from 90..100, it wouldn't be black. It would rescale.
 

Related to Using 2 color functions in a mathematica matrix plot

1. What is a matrix plot in Mathematica?

A matrix plot in Mathematica is a type of data visualization that displays a matrix of values as a grid of colored squares. Each square is assigned a color based on the value it represents, allowing for easy identification of patterns and trends within the data.

2. How do I plot a matrix in Mathematica using 2 color functions?

To plot a matrix using 2 color functions, you can use the MatrixPlot function in Mathematica. This function allows you to specify 2 different color functions, one for positive values and one for negative values, which will be applied to the corresponding cells in the matrix.

3. Can I customize the colors used in a matrix plot?

Yes, you can customize the colors used in a matrix plot by specifying the color function to be used. You can either choose from the predefined color functions in Mathematica or create your own custom color function using the ColorData function.

4. How can I add a color legend to my matrix plot?

To add a color legend to your matrix plot, you can use the Legended function in Mathematica. This function allows you to specify the color function and the corresponding range of values for the legend, as well as customize the appearance of the legend itself.

5. Can I combine a matrix plot with other types of plots in Mathematica?

Yes, you can combine a matrix plot with other types of plots in Mathematica by using the Show function. This allows you to display multiple plots together, such as a matrix plot and a line plot, in the same figure for a more comprehensive visualization of your data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
311
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
535
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
974
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
841
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
761
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
970
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top