Legend

These IronPython scripts below show how to modify any of the Scatter Plot visualization settings found on the Legend tab of the Scatter Plot Properties dialog box in the Spotfire user interface.
Note

In each of the scripts below, it is assumed that the MyVis variable references the targeted visualization. See here for more information about referencing visualizations.

Show or Hide the Legend:

from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()

#Hide the legend
myVis.Legend.Visible = False

Change the Legend Position:

The script below is equivalent to selecting “Right” or “Left” under “Position:” on the Legend tab.

from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()

#Dock the legend to the right or left
myVis.Legend.Dock = LegendDock.Right
# OR
myVis.Legend.Dock = LegendDock.Left

Change Legend Item Visibility Options:

This script shows how to update visibility options for individual legend items using the “if … elif … else” pattern, as shown below. To adapt this code to your needs, simply set i.Visible, i.ShowTitle, or i.ShowAxisSelector to True or False as desired under each legend item title.

The Visible property shows or hides the legend item completely, the ShowTitle property checks or unchecks the “Show title” checkbox at the bottom of the Legend tab, and the ShowAxis property checks or unchecks the “Show axis selector” checkbox for that specific legend item. Notice that ShowTitle and ShowAxis are not available for some of the legend items. This constraint is shown in the Spotfire user interface as a “grayed-out” checkbox when these legend items are selected.

To shorten the script below, you can delete any of the elif statements for legend items that you want hidden completely. The else statement at the bottom of the script will hide any legend item that was not caught by the prior if/elif statements.

from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()

for i in myVis.Legend.Items:
    if i.Title == "Title":
        i.Visible = True
    elif i.Title == "Description":
        i.Visible = True
    elif i.Title == "Data limiting":
        i.Visible = True
    elif i.Title == "Data table":
        i.Visible = True
        i.ShowTitle = True
    elif i.Title == "Marking":
        i.Visible = True
        i.ShowTitle = True
    elif i.Title == "Show/hide":
        i.Visible = True
        i.ShowTitle = True
    elif i.Title == "Trellis by":
        i.Visible = True
        i.ShowTitle = True
    elif i.Title == "Color by":
        i.Visible = True
        i.ShowTitle = True
        i.ShowAxisSelector = True
    elif i.Title == "Lines and curves":
        i.Visible = True
    elif i.Title == "Error bars":
        i.Visible = True
    else:
        i.Visible = False  #Hide any legend items not caught above

Change the Legend Width:

The IronPython script below changes the legend’s width in pixels. In the Spotfire user interface, this is done by clicking and dragging the vertical edge of a legend to make it wider or narrower.

from Spotfire.Dxp.Application.Visuals import *

myVis = myVis.As[Visualization]()

myVis.Legend.Width = 150  #Width in pixels
Welcome!

The purpose of this website is to provide a comprehensive, accurate, and efficient IronPython reference for Spotfire developers.