# Assigning labels to numbers in ListContourPlot

I am trying to plot some 2D data using ListContourPlot. The quantity to be plotted has only three discrete values 0, 1, 2. While plotting them, I want to assign these numbers some labels say A, B, C, D to be shown as legends. The extra label D (four labels for three values) is added because the other data set I want to plot and compare with present data set has four variables (0, 1, 2, 3) and I want the color code to remain same. I created the legends separately and Legended it with the Plot, as in the following working example. Now, I am facing two problems.

1. How to fix a numerical value to a particular label, say 0 for A, 1 for B etc. The problem is that for different data sets, same color is assigned to different labels/numerical value !!
2. In this working example, there are only three values 0, 1 and 2, so I should see only three colors, but I see more. How is it possible ?

Will appreciate any help on this.

XX = {{0., 0., 0}, {0.149508, 0.076178, 0}, {0.153488, 0.0498713,
0}, {0.156435, 0., 0}, {0.302952, 0.0984348, 0}, {0.309017, 0.,
0}, {0.444473, 0.144418, 1}, {0.451668, 0.0715374, 1}, {0.453991,
0., 0}, {0.574342, 0.186615, 1}, {0.584501, 0.0925761,
0}, {0.587786, 0., 0}, {0.689152, 0.223919, 2}, {0.702713,
0.111299, 1}, {0.707107, 0., 0}};
plot = ListContourPlot[XX, ColorFunction -> "RedBlueTones"];
labels = { "A" , "B", "C", "D" };
legend = SwatchLegend["RedBlueTones", labels,
LegendMarkerSize -> {{20, 20}}];
Legended[plot, legend]

• Try the option Contours->{0,1,2} – Ulrich Neumann Oct 19 '19 at 14:36
• Thanks. I tried, and number of colors reduced. Also, how to assign a label to a number ? – user49535 Oct 19 '19 at 15:02
• This is a strange use case for a contour plot... – C. E. Oct 19 '19 at 20:04
• Could there be any alternative ? – user49535 Oct 20 '19 at 7:54