Sometimes when there are lot of values in column used for Color axis of Visualization, it becomes tedious to change the colors of some values in one color scheme with some other color from other color scheme manually. At that time, there is need to merge colors from two color schemes which can be done using Iron Python script.
Introduction
Sometimes when there are lot of values in column used for Color axis of Visualization, it becomes tedious to change the colors of some values in one color scheme with some other color from other color scheme manually. At that time, there is need to merge colors from two color schemes which can be done using Iron Python script.
Once you have colors merged, it can then be saved as Document color scheme as shown here and if required, merged document color scheme can be applied to other visualizations as well.
Code Sample
# Copyright © 2020. TIBCO Software Inc. Licensed under TIBCO BSD-style license. from Spotfire.Dxp.Application.Visuals import * from Spotfire.Dxp.Application.Visuals import CategoryKey from System.Drawing import Color from System.Collections.Generic import List from Spotfire.Dxp.Framework.Library import * vc= vis.As[VisualContent]() #vis is the script parameter for visualization containing color scheme 1 vc1= vis2.As[VisualContent]() #vis2 is the script parameter for visualization containing color scheme 2 #Get Categories based on expression keys=List[CategoryKey]() keys=vc.ColorAxis.Coloring.AddCategoricalColorRule().GetExplicitCategories() list1=[] color1=[] ## List of values whose colors need to be picked from color scheme 1 string1="MW,NE" for k in keys: if string1.find(str(k))!=-1 and str(k) != '': list1.append(k) color1.append(vc.ColorAxis.Coloring.GetColorForCategory(k)) ## All other values except above 2 will be picked from color scheme 2 list2=[] color2=[] keys1=List[CategoryKey]() keys1=vc1.ColorAxis.Coloring.AddCategoricalColorRule().GetExplicitCategories() for k1 in keys1: if string1.find(str(k1))==-1 and str(k1) != '': list2.append(k1) color2.append(vc1.ColorAxis.Coloring.GetColorForCategory(k1)) ## Merge colors ##### vc3=vis3.As[VisualContent]() #vis3 is the script parameter for visualization where merged color scheme would be applied #Get Categories based on expression keys3=List[CategoryKey]() keys3=vc3.ColorAxis.Coloring.AddCategoricalColorRule().GetExplicitCategories() #Add colors to each category for i in range(len(list1)): vc3.ColorAxis.Coloring.SetColorForCategory(list1[i], color1[i]) for j in range(len(list2)): vc3.ColorAxis.Coloring.SetColorForCategory(list2[j], color2[j])
References
- API Reference: ColoringTemplateCollection class
- API Reference: Coloring
- API Reference:CategoryColorRule
- API Reference: CategoryKey
License: TIBCO BSD-Style License
Attachment
Download attachment from resources
Back to IronPyton Scripting in Spotfire Examples: https://community.spotfire.com/s/article/IronPython-Scripting-in-Spotfire
Recommended Comments
There are no comments to display.