21

Possible Duplicate:
Labelling ArrayPlot Charts

I am making a MatrixPlot. For example, consider the following:

list = {{1, 1, 0, 1}, {0, 0, 1, 1}, {1, 0, 1, 0}};
MatrixPlot[list]

which yields:

MatrixPlot

But now suppose I want to label the axes with other numbers. For example, I would like to label the ticks on the horizontal axis as 101, 167, 188, 205 (as they are not now), and the ticks on the vertical axis as 1, 2, 3 (as they already are). I know this is a strange request, but it is because I would like to label the horizontal axis according to "particle number" (which is an integer in my application).

Or maybe a better way to phrase the question is, is it possible to label axis/frame ticks with any arbitrary string (for example, labeling the horizontal axis with "Alice", "Bob", "Carla", and "David")? One possibility seems like FrameTicks, but I can't seem to figure out if it can be used to map strings.

If I use

list = {{1, 1, 0, 1}, {0, 0, 1, 1}, {1, 0, 1, 0}};
MatrixPlot[list, 
 FrameTicks -> {{{1, 2, 3}, None}, {{101, 167, 188, 205}, None}}]

I get:

MatrixPlot

because, of course, FrameTicks thinks I'm referring to which discrete values to label.

Also, if I try:

list = {{1, 1, 0, 1}, {0, 0, 1, 1}, {1, 0, 1, 0}};
MatrixPlot[list, 
 FrameTicks -> {{{1, 2, 3}, None}, {{"101", "167", "188", "205"}, 
    None}}]

I get "Not a valid tick specification."

Do you have any other ideas?

Andrew
  • 10,569
  • 5
  • 51
  • 104
  • 1
    I believe this was covered in http://mathematica.stackexchange.com/questions/6043/is-there-a-way-to-make-the-tick-marks-larger. – DavidC Jun 08 '12 at 16:11
  • 1
    This doesn't work because the frame ticks specification needs positions to determine where to place the labels. If you use numbers mma assumes positions == labels, and with the high values you're using they are out of the plot range. In the case of the strings as labels there is no position information at all. – Sjoerd C. de Vries Jun 08 '12 at 17:39
  • 3
    This question is about something qualitatively different than the above-referenced question. FDSg's answer below is correct, and this should not be marked as a duplicate. – Steven Bedrick Nov 06 '13 at 00:19
  • @StevenBedrick Can we change it from not duplicate to duplicate? This question was directly useful to me where as the other answer was not. – olliepower Jun 15 '15 at 21:11

1 Answers1

37

try this

 MatrixPlot[list,  
 FrameTicks -> {
 {{1, 2, 3}, None}, {{{1, 101}, {2, 167}, {3, 188}, {4, 205}}, {{1, "Alice"}, {2,"Bob"}}}
 }]

enter image description here

FDSg
  • 1,805
  • 1
  • 17
  • 17