# How to best visualize data when outliers lead to lack of contrasting colors for the rest of the plot?

I have plotted the following map of Philippines according to the population in its regions, using matplotlib.pyplot in Python 3:

As can be seen, there's one province (in red) that is an outlier. When looking at the data, it is clear:

 population = [16.892118644067804,
27.13259740259741,
27.325479452054793,
25.502352941176472,
29.62087999999999,
25.593870967741932,
27.649384615384616,
25.38908450704225,
26.924931506849322,
26.636250000000004,
27.317105263157895,
26.58338345864662,
29.48689393939393,
28.283986013986016,
26.563118279569903,
23.037142857142857,
24.2674]


This is making the plot "unattractive" - there would have been a lot more contrasting colors for the other regions had this one region's data not been an outlier. What options do I have to rectify this?

1. Remove this region's data. In that case, this region would appear white (uncolored), and the rest will have contrasting colors. But for whatever reason, that's not an option for me currently.
2. Manually tweak that one data point to "blend in" with the other data points (something like a mean of all the other data points, or even a handcrafted value that is reasonably close to the other data points, like 22, or whatever). I tried this, and this does give more contrasting colors. The trouble is, this is misrepresentation of data. So, if possible, I would like to avoid it.
3. Stretch the yellow further down in the colormap, so that only a little space is given to red. That is, instead of the 2 colors starting to transition from one to the other around 24 in the colorbar, it should do so around, say, 19. Anybody knows how to do that?

Any other ideas? What are some of the best practice approaches to tackle this issue?

• Is it better if you take the log value? – TQA Jun 26 '18 at 5:11
• You could manually set color range. Right now it is using default from your minimum value of 16.89 to max value of 29.62. You pyplot.clim() to change this range to something like (0, 30). – tomar__ Jun 26 '18 at 16:39
• @tomar__ I have already tried. It doesn't produce the desired results. All regions are either "undercolored" (light) or "overcolored" (bright). – Kristada673 Jun 27 '18 at 2:00

With Wolfram Language you may use GeoRegionValuePlot with the ColorFunction option to customise the colour scaling.

With some "AdministrativeDivision" "Population" data for the Philippines.

popPH = EntityValue[
"Population",
"EntityAssociation"];

First@Normal@popPH


Then GeoRegionValuePlot with and without a custom ColorFunction.

linear = GeoRegionValuePlot[popPH,
ColorFunction -> ColorData["SolarColors"],
PlotLabel -> "Linear ColorFunction",
PlotLegends -> Placed[Automatic, Below]
];

log = GeoRegionValuePlot[popPH,
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["SolarColors"][
Rescale[Log@#, Log@QuantityMagnitude@MinMax[popPH]]] &),
PlotLabel -> "Log ColorFunction",
PlotLegends -> Placed[Automatic, Below]
];

Row[{linear, log}]


Hope this helps.

I would recommend two simple but effective methods:

1. Outliers like that are usually easy to discover by calculating the mean and std of the values and possibly you could set your interval of colors between: $$[\mu-\sigma,\mu+\sigma]$$. This would 'clip' the outliers toward a generic maximum.

2. Binning - Instead of giving a specific color to specific country choose a sufficient bin number and group some countries together. You can think about it this way - Does 26.924931506849322 and 26.636250000000004 are really any different? You can have a parametric amount of bins by using it as function of the amount of items you have. Like: $${countries}/{2}$$.