Jump to content

IronPython: how to apply "color by unique values" for visualization


Charles Randall 2

Recommended Posts

Hello,

 

I am trying to write an IronPython script that will automatically set colors based on unique values in a column (e.g., "1" gets one color, "2" gets a different color, etc.). Here's an example image (using entirely made-up "data"):

 

 

However, I cannot find a good way to automate this with IronPython; the code I currently have is this:

visualization.ColorAxis.Coloring.Clear()

visualization.ColorAxis.Coloring.AddCategoricalColorRule()

visualization.ColorAxis.Expression = "[" + colNameToColorBy + "]"

However, the block of code needs to be run twice - for some reason, if it gets run only once, I end up with a continuous ColorRule:

 

I have tried commenting out various lines when putting two copies of the code block back-to-back, to see if only one part of it needs to be run twice, but it only seems to work as expected when the entire block runs twice.

Also, since there is no mention of the color scheme (I would like to keep using the built-in "Spotfire categorical" scheme), or the fact that the categories are automatically getting assigned, I am concerned that it would not be a robust solution even if it did behave as I expected.

 

If anybody could share some advice/information on either a) a better way to achieve this via IronPython, or b) why the code I have is behaving the way it is, it would be very much appreciated!

 

Thank you very much,

Charles

 

 

Edit: I seem to have solved my issue by putting around the column name in the ColorAxis expression instead of just []. Whoops!

Link to comment
Share on other sites

To add images/screenshots, try using one of the following two methods:

 

a) To add the screenshot inline, use the Media Browser that is available in the toolbar when writing/editing a post.OR

 

b) To add the screenshot as an attachment, use the Attachments section and add your file there.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...