Message Boards Message Boards

GROUPS:

Issue with ColorFunction in GeoRegionValuePlot?

Posted 2 months ago
732 Views
|
8 Replies
|
0 Total Likes
|

I have a list of towns with numbers assigned (population changes). I want to colour the towns green or red according to whether their population changes are positive or negative. My thought was I would use a custom ColorFunction as follows:

ColorFunctionScaling -> False, ColorFunction -> (If[# > 0, Green, Red] &)

However, this does not work. All the points come out red, even though many are positive. If I set the threshold for distinguishing green from red at -5600, then it acts as though the threshold is somewhere around 0. In general, the colouring of points on the map does not reflect the threshold I use in the ColorFunction.

I have played around and reproduced the problem in simple form as follows:

GeoRegionValuePlot[{Entity[
    "City", {"London", "GreaterLondon", "UnitedKingdom"}] -> 334, 
  Entity["City", {"Paris", "IleDeFrance", "France"}] -> 356, 
  Entity["City", {"Berlin", "Berlin", "Germany"}] -> 399}, 
 ColorFunctionScaling -> False, 
 ColorFunction -> (If[# > 358, Green, Red] &)]

Clearly, London and Paris should be coloured red (their values are less than 358) while Berlin should be coloured green. However, the actual result gives Paris as green, falsely implying that its value (356) is greater than the threshold of 358.

GeoRegionValuePlot problem

8 Replies

I'm using Version 10.1 running Windows 7. Executing code in your In[161], Paris and London were red and Berlin was green.

Hi,

I am on a Mac and if I execute:

GeoRegionValuePlot[{Entity[
    "City", {"London", "GreaterLondon", "UnitedKingdom"}] -> 334, 
  Entity["City", {"Paris", "IleDeFrance", "France"}] -> 356, 
  Entity["City", {"Berlin", "Berlin", "Germany"}] -> 399}, 
 ColorFunctionScaling -> False, 
 ColorFunction -> (If[# > 358, Green, Red] &)]

I get

enter image description here

as in the OP. I get the same if I execute that in the Wolfram Cloud.

Cheers,

Marco

Posted 2 months ago

I'm using Version 11.3 on Windows 8.1. I've checked with Version 11.2, and I get the same.

Posted 2 months ago

I continue to investigate this, and I don't seem to be able to find any workaround. Nothing works as I would expect. I have tried setting ColorFunctionScaling->True, and setting my thresholds to the resulting normalised values, but this gives incomprehensible results--for example, even though all values are positive and I set the threshold at 0, they are all coloured red as if below the threshold.

Other bizarre behaviour...

Trying a different approach to defining a ColorFunction using Hue (not useful for my intended purpose but just testing the performance of this function)...

GeoRegionValuePlot[{Entity[
    "City", {"London", "GreaterLondon", "UnitedKingdom"}] -> 0.1, 
  Entity["City", {"Paris", "IleDeFrance", "France"}] -> 0.4, 
  Entity["City", {"Berlin", "Berlin", "Germany"}] -> 0.7}, 
 ColorFunctionScaling -> False, ColorFunction -> Function[u, Hue[u]]]

GeoRegionValuePlot problem 1

Looks feasible. I then change the value of London, which should not change the colours of the other two cities, since their values do not change, but in fact it does.

GeoRegionValuePlot[{Entity[
    "City", {"London", "GreaterLondon", "UnitedKingdom"}] -> 0.2, 
  Entity["City", {"Paris", "IleDeFrance", "France"}] -> 0.4, 
  Entity["City", {"Berlin", "Berlin", "Germany"}] -> 0.7}, 
 ColorFunctionScaling -> False, ColorFunction -> Function[u, Hue[u]]]

This gives...

GeoRevionValuePlot problem 2

I think, maybe it is acting as though ColorFunctionScaling is True (even though I set it to false). In this case, changing the value of London changes the minimum value, which affects the scaling. So I try changing the value for Paris, which is between the extremes. In this case, it looks as though the ColorFunction is behaving in some quantised way, even though it ought to be continuous.

With Paris changed to 0.3

GeoRegionValuePlot[{Entity[
    "City", {"London", "GreaterLondon", "UnitedKingdom"}] -> 0.1, 
  Entity["City", {"Paris", "IleDeFrance", "France"}] -> 0.3, 
  Entity["City", {"Berlin", "Berlin", "Germany"}] -> 0.7}, 
 ColorFunctionScaling -> False, ColorFunction -> Function[u, Hue[u]]]

I get the following, where Paris is now coloured the same as London...

GeoRegionValuePlot problem 3

And if I change Paris to 0.5...

GeoRegionValuePlot[{Entity[
    "City", {"London", "GreaterLondon", "UnitedKingdom"}] -> 0.1, 
  Entity["City", {"Paris", "IleDeFrance", "France"}] -> 0.5, 
  Entity["City", {"Berlin", "Berlin", "Germany"}] -> 0.7}, 
 ColorFunctionScaling -> False, ColorFunction -> Function[u, Hue[u]]]

I get the following, where Paris seems to be coloured the same as when its value is 0.4 (even though Hue[0.5] ought to look different from Hue[0.4]...

GeoRegionValuePlot problem 4

I'm beginning to think that ColorFunction within GeoRegionValuePlot got broken somewhere between Mathematica 10 and Mathematica 11.3, with no logical explanation or workaround, and so it is now impossible to achieve what I want..?

Posted 2 months ago

Did you try doing this in an earlier version of the software, Marc?

Posted 2 months ago

I have not tried this in an earlier version.

I have found a workaround by first mapping the data onto their colours, then passing the new data to GeoRegionValuePlot. I.e., I do

data2 = Map[#[[1]] -> If[#[[2]] > 0, Green, Red] &, data]
GeoRegionValuePlot[data2]

I reported the bug to Support so that it will be addressed in the upcoming Version 12.

Regards,

Posted 2 months ago

Thank you very much.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract