# How to label fields in text format in MatrixPlot?

**URL:** <https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799>\
**Category:** Questions\
**Tags:** graphics-and-visualization\
**Created:** [March 23, 2022, 8:33pm UTC](https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799 "2022-03-23T20:33:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![predecessor77](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/predecessor77/32/6262_2.png) [@predecessor77](https://community.wolfram.com/u/predecessor77)\
**Post date:** [March 23, 2022, 8:33pm UTC](https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799/1 "2022-03-23T20:33:46Z")

</div>

data = {\<|“ID” → “y1”, “x1” → 8.454545454545455`, "x2" -> 6.`,  
“x3” → 46.36363636363637`, "x4" -> 7.818181818181818`,  
“x5” → 17.15909090909091`|>, <|"ID" -> "y2", "x1" -> 11.909090909090908`, “x2” → 13.583333333333334`, "x3" -> 12.818181818181818`, “x4” → 11.909090909090908`, "x5" -> 12.554924242424242`|\>, \<|“ID” → “y3”,  
“x1” → 9.454545454545455`, "x2" -> 9.25`,  
“x3” → 9.909090909090908`, "x4" -> 10.`,  
“x5” → 9.65340909090909`|>, <|"ID" -> "y4", "x1" -> 34.666666666666664`, “x2” → 32.45454545454545`, "x3" -> 31.166666666666668`, “x4” → 30.727272727272727`, "x5" -> 32.25378787878788`|\>};  
ytick = data[[All, 1]];  
xtick = Rest@Keys@First@data;  
MatrixPlot[Values@data[[All, 2 ;;]],FrameTicks → {{ytick, None}, {None, xtick}}]

MatrixPlot does not accept FrameTicks in text format.

How to plot the following figure?

 ![fig1.png](https://global.discourse-cdn.com/wolfram/original/3X/d/d/ddb073d56840f15716235a80c9d02260d7326e5d.png)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [March 23, 2022, 9:04pm UTC](https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799/2 "2022-03-23T21:04:36Z")

</div>

Hi Ming-Chou

The ticks need to be paired with an index

```
ytickValues = Style[#, 22, Bold, Black] & /@ data[[All, 1]];
xtickValues = Style[#, 22, Bold, Black] & /@ Rest@Keys@First@data;

ytick = Transpose[{Range@Length@ytickValues, ytickValues}];
xtick = Transpose[{Range@Length@xtickValues, xtickValues}];

MatrixPlot[Values@data[[All, 2 ;;]], FrameTicks -> {{ytick, None}, {None, xtick}}]

```

 ![2498plot.png](https://global.discourse-cdn.com/wolfram/original/3X/2/9/2952b256d1d561fa9c830050866378548b5304d0.png)

---

<div class="post-metadata">

**Author:** ![predecessor77](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/predecessor77/32/6262_2.png) [@predecessor77](https://community.wolfram.com/u/predecessor77)\
**Post date:** [March 24, 2022, 5:57am UTC](https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799/3 "2022-03-24T05:57:25Z")

</div>

I found that Spacings is not an option for MatrixPlot.

Is it possible to adjust the width of individual cells?

For example, the label string length in the last line is greater than the other line.

3Q~~

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [March 24, 2022, 4:26pm UTC](https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799/4 "2022-03-24T16:26:35Z")

</div>

Not sure what you mean by

> Is it possible to adjust the width of individual cells?

You can use the `AspectRatio` option to change the relative width and height of the cells.

You can use

```
Mesh -> All,
MeshStyle -> Directive[Thickness[.005], White],

```

to add a uniform spacing between cells.

Also not sure what you mean by

> For example, the label string length in the last line is greater than  
> the other line

Do you mean that y4 is wider than y1? If so, you could try using a fixed-width font for the labels.

---

<div class="post-metadata">

**Author:** ![predecessor77](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/predecessor77/32/6262_2.png) [@predecessor77](https://community.wolfram.com/u/predecessor77)\
**Post date:** [March 25, 2022, 3:22am UTC](https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799/5 "2022-03-25T03:22:17Z")

</div>

![圖片1.png](https://global.discourse-cdn.com/wolfram/original/3X/6/3/63a3ec0c530229891d0f1efe9500064ae83a781d.png)

---

<div class="post-metadata">

**Author:** ![rohitnamjoshi](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rohitnamjoshi](https://community.wolfram.com/u/rohitnamjoshi)\
**Post date:** [March 25, 2022, 2:20pm UTC](https://community.wolfram.com/t/how-to-label-fields-in-text-format-in-matrixplot/19799/6 "2022-03-25T14:20:27Z")

</div>

Some options

1. Use a smaller font size. You could choose a font size based on the length of the label but I think that would look bad
2. Use an `AspectRatio` less than 1
3. Increase `ImageSize`
4. Rotate the labels

 ![10620plot.png](https://global.discourse-cdn.com/wolfram/original/3X/8/d/8d8aea629dbe4752582f390edaa40fed7c5188de.png)
