How to get the symbology colors?

2103
9
Jump to solution
12-05-2017 10:33 AM
RobertIancu
New Contributor

I have a layer for which the symbology is Unique Values. Is there any way I can access the colors for each value using python? I would like to get the colors so that I can make a pie chart using matplotlib that matches the symbol colors. How would I go about this?

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

If you are using ArcGIS Pro, it is possible to retrieve the color values since they have added more renderer classes, including UniqueValueRenderer—ArcPy | ArcGIS Desktop.

If you are using ArcMap/ArcCatalog, and don't mind using undocumented ArcPy methods, you can use lyr._arc_object.getsymbology() to dump a JSON definition of the symbology that will include color codes.

View solution in original post

9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

via python... no

manually recording them via the symbolizer, or free color pickers that work independently

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you are using ArcGIS Pro, it is possible to retrieve the color values since they have added more renderer classes, including UniqueValueRenderer—ArcPy | ArcGIS Desktop.

If you are using ArcMap/ArcCatalog, and don't mind using undocumented ArcPy methods, you can use lyr._arc_object.getsymbology() to dump a JSON definition of the symbology that will include color codes.

RandyBurton
MVP Regular Contributor

Nice trick Joshua Bixby‌.  I tried the lyr._arc_object.getsymbology() in  version 10.2.1.  Looks like it gives RGB and a transparency? value.  (Additional note:  This isn't a perfect way as it sometimes gets the wrong style and no colors  -- which is probably why it is undocumented.)

I created a copy of ArcMap's standard color selections as an Excel spreadsheet (attached).  It displays a color swatch along with RGB values and a gray-scale value.  I will print the sheet to see what the colors will look like when printed on different printers.  For custom colors, you will need to note the RGB value.

RobertIancu
New Contributor

Thank you! You saved my project! lyr._arc_object.getsymbology() is certainly a nice trick though I am confused as to why this is the only way of achieving this issue

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Glad it works for you.  I would say it has been address, in ArcGIS Pro.  More and more, Esri Development is focusing on addressing issues in Pro and backporting them if it isn't too much work.

0 Kudos
MarceloRosensaft
New Contributor III

Hello,

I've just seen your comment that refers to the UniqueValueRenderer in arcpy.mp, which I'm trying not to use because most of my users still need MXds.

Do you think it's possible to create a symbology from another symbology? I mean that I have a unique values symbology  - a layer file - applied to a certain value field and I need to prepare a parallel symbology for another value field, meaning that everything will be the same - labels, descriptions and mainly the polygons color and pattern - but for a different set of values.

If there were examples, more than the two shown in the ESRI page, I'd appreciate getting links to them.

Thanks much,

Marcelo

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

See updateLayerFromJSON from Layer—Help | Documentation , and there is a good example at Update layer symbology with arcpy · GitHub 

MarceloRosensaft
New Contributor III

Thank you! I'll look into it

0 Kudos
MarceloRosensaft
New Contributor III

Thank you so much, Joshua Bixby.

It worked perfectly!

0 Kudos