Group Abstract Group Abstract

Message Boards Message Boards

Issue with ColorFunction in GeoRegionValuePlot?

Posted 7 years ago

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

POSTED BY: Marc Widdowson
12 Replies
Posted 4 years ago

Can confirm this issue again in Mathematica version 12.2 on Windows 10 build 19042.844 64-bit.

Marc's work-around still works. Needed to create a GeoRegionValuePlot to update an analysis with new data and ran into this and a few more issues.

Unfortunately, the situation seems to have gotten a bit worse: using your own ColorFunction no longer works (it used to show some incorrect results). Replacing the legend using this method /._Barlegend->Legend also no longer seems to work.

To my surprise I no longer seem to be able to create a plot overlay with Show[{GeoRegionValuePlot ,GeoListPlot,GeoGraphics}].

This generates e.g.

  • Rule::argr: Rule called with 1 argument; 2 arguments are expected.
  • Could not combine the graphics objects in Show

I will look into it a bit further, but the individual Geo plots can be created successfully, but when combined in Show, Mathematica throws an error.

POSTED BY: Dave Middleton
Posted 5 years ago

I am seeing a similar issue. I am using Mathematica 12.2.0.0 on Mac OS10.15.7. Is this still a bug? Is there a solution besides mapping the data as shared by Marc (above)? P.S. This is my first post so I'm not sure how this works...

bl = BarLegend[{palette, {0, 4}}, LabelStyle -> 10];

getColor[val2_] := ColorData["TemperatureMap", val2/4];

{getColor[.1], getColor[1], getColor[1.5], getColor[2], getColor[2.5],
  getColor[3], getColor[3.5], getColor[4]}

gPlot = <|Entity[
    "AdministrativeDivision", {"FairfieldCounty", "Connecticut", 
     "UnitedStates"}] -> Log10[10000.], 
  Entity["AdministrativeDivision", {"HartfordCounty", "Connecticut", 
     "UnitedStates"}] -> Log10[5000.], 
  Entity["AdministrativeDivision", {"LitchfieldCounty", "Connecticut",
      "UnitedStates"}] -> Log10[1000.], 
  Entity["AdministrativeDivision", {"MiddlesexCounty", "Connecticut", 
     "UnitedStates"}] -> Log10[500.], 
  Entity["AdministrativeDivision", {"NewHavenCounty", "Connecticut", 
     "UnitedStates"}] -> Log10[100.], 
  Entity["AdministrativeDivision", {"NewLondonCounty", "Connecticut", 
     "UnitedStates"}] -> Log10[50.], 
  Entity["AdministrativeDivision", {"TollandCounty", "Connecticut", 
     "UnitedStates"}] -> Log10[10.], 
  Entity["AdministrativeDivision", {"WindhamCounty", "Connecticut", 
     "UnitedStates"}] -> Log10[5.]|>

GeoRegionValuePlot[gPlot,
 ImageSize -> 400,
 PlotRange -> {0, 4},
 ColorFunction -> (getColor[#] &),
 ColorFunctionScaling -> False,
 PlotLegends -> bl,
 PlotStyle -> Directive[Opacity[.6]]]

Result

POSTED BY: Mark Firary

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

Regards,

POSTED BY: Neil Singer
Posted 7 years ago

Thank you very much.

POSTED BY: Marc Widdowson
Posted 6 years ago

The bug is still there in Version 12, unfortunately.

POSTED BY: Updating Name
Posted 7 years ago

Did [url=http://www.testlink.com/]test link[/url] you try doing this in an earlier version of the software, Marc?

POSTED BY: Cole Rothier
Posted 7 years ago
POSTED BY: Marc Widdowson
Posted 5 years ago

Thanks for sharing the workaround, Marc. I used it to ensure the correct color values in the RegionValuePlot in Mathematica version 12.

Today, I ran into an issue with a custom ColorFunction in RegionValuePlot, which showed colors for US Sates inconsistent with their corresponding values.

Cheers,

Dave

POSTED BY: Dave Middleton
Posted 7 years ago
POSTED BY: Marc Widdowson
Posted 7 years ago

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

POSTED BY: Marc Widdowson
POSTED BY: Marco Thiel

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

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