2
$\begingroup$

I have the following piece of code that plots a colormap by zipcode.

Zips is an array of zip codes (All in the US mainland) and testscore is just some made up data for testing purposes.

The list of usable zipcodes can be found here or here.

zips = ToString /@ zips;
zipcheck[x_] := If[StringLength[x] < 5, StringJoin["0", x], x];
zips = zipcheck /@ zips;
entmaker[x_] := Entity["ZIPCode", ToString[x]];
entzip = entmaker /@ zips;
n = Dimensions[zips][[1]]
testscore = RandomReal[{0, 1}, n];
GeoRegionValuePlot[Rule @@@ Transpose[{entzip, testscore}],ColorFunction -> "AvocadoColors",MissingStyle -> Directive[Opacity[1.0], White, EdgeForm[Dashed]],ColorFunctionScaling -> True, PlotStyle -> Opacity[1.],PlotLegends -> BarLegend[Automatic]]

So far the plot takes about 30 min to produce a plot. Any ideas on how to speed up the code?

$\endgroup$
6
  • 1
    $\begingroup$ The slow part is likely the conversion of the ZIP codes to regions that can be processed by GeoRegionValuePlot[]; separate that out from the plotting. $\endgroup$
    – J. M.'s torpor
    Mar 26 '19 at 1:42
  • $\begingroup$ How can I force the data to be processed without being plotted? $\endgroup$ Mar 26 '19 at 13:52
  • $\begingroup$ Perhaps something like EntityValue[#, EntityProperty["ZIPCode", "Polygon"]] & /@ entzip. $\endgroup$
    – J. M.'s torpor
    Mar 26 '19 at 13:58
  • $\begingroup$ I see, then pass that with "testscore" into the GeoRegionValuePlot[] $\endgroup$ Mar 26 '19 at 13:59
  • 2
    $\begingroup$ EntityValue[entzip, "Polygon"] should be faster than mapping. 1 API call vs many. $\endgroup$
    – Chip Hurst
    Mar 26 '19 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.