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?
Solved! Go to Solution.
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.
via python... no
manually recording them via the symbolizer, or free color pickers that work independently
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.
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.
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
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.
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
See updateLayerFromJSON from Layer—Help | Documentation , and there is a good example at Update layer symbology with arcpy · GitHub
Thank you! I'll look into it
Thank you so much, Joshua Bixby.
It worked perfectly!