[vtkusers] Set the Color of each line in vtkChartParallelCoordinates

Eric E. Monson emonson at cs.duke.edu
Thu Oct 13 09:39:17 EDT 2011


Hello,

When I color by category I do use a lookup table, but only have it filled with the colors I have specified myself. Then I use integers to define the categories and have the lookup table mapping the range of those values to colors. I'll attach a variation on that test that I use (sorry it's a little messy, and in Python).

-Eric

· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
Eric E Monson
Duke Visualization Technology Group

-------------- next part --------------
A non-text attachment was scrubbed...
Name: pcoords_cats.png
Type: image/png
Size: 50871 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111013/bcc6934d/attachment.png>
-------------- next part --------------
===================

# Translated to Python from [VTK]/Charts/Testing/Cxx/TestPCPlot.cxx

import vtk
import math
import random

# Set up a 2D scene, add an XY chart to it
view = vtk.vtkContextView()
view.GetRenderer().SetBackground(1.0, 1.0, 1.0)
view.GetRenderWindow().SetSize(600,300)

chart = vtk.vtkChartParallelCoordinates()
view.GetScene().AddItem(chart)

# Test charting with a few more points...
numPoints = 100
numCats = 8
inc = 7.5 / (numPoints-1)

# Create arrays that will end up as table columns
arrX = vtk.vtkFloatArray()
arrX.SetName("XAxis")
arrX.SetNumberOfComponents(1)
arrX.SetNumberOfTuples(numPoints)
arrC = vtk.vtkFloatArray()
arrC.SetName("Cosine")
arrC.SetNumberOfComponents(1)
arrC.SetNumberOfTuples(numPoints)
arrS = vtk.vtkFloatArray()
arrS.SetName("Sine")
arrS.SetNumberOfComponents(1)
arrS.SetNumberOfTuples(numPoints)
arrS2 = vtk.vtkFloatArray()
arrS2.SetName("GaussRand")
arrS2.SetNumberOfComponents(1)
arrS2.SetNumberOfTuples(numPoints)

arrCat = vtk.vtkIntArray()
arrCat.SetName("Category_ids")
arrCat.SetNumberOfComponents(1)
arrCat.SetNumberOfTuples(numPoints)

# For some reason table.SetValue() is not wrapped
# 	so need to build arrays and then add as columns
# Would be more elegant to use numpy, but wanted to keep it out for now...
for i in range(numPoints):
	arrX.SetTuple1(i, i * inc)
	arrC.SetTuple1(i, math.cos(i * inc) + 0.0)
	arrS.SetTuple1(i, math.sin(i * inc) + 0.0)
	arrS2.SetTuple1(i, random.gauss(0,1))
	arrCat.SetTuple1(i, int(float(numCats)*float(i)/float(numPoints)))

# Create a table with some points in it...
table = vtk.vtkTable()
table.AddColumn(arrX)
table.AddColumn(arrC)
# table.AddColumn(arrS2)
table.AddColumn(arrS)
table.AddColumn(arrCat)

cl = []
cl.append([float(cc)/255.0 for cc in [27, 158, 119]])	# Colorbrewer Dark2
cl.append([float(cc)/255.0 for cc in [217, 95, 2]])
cl.append([float(cc)/255.0 for cc in [117, 112, 179]])
cl.append([float(cc)/255.0 for cc in [231, 41, 138]])
cl.append([float(cc)/255.0 for cc in [102, 166, 30]])
cl.append([float(cc)/255.0 for cc in [230, 171, 2]])
cl.append([float(cc)/255.0 for cc in [166, 118, 29]])
cl.append([float(cc)/255.0 for cc in [102, 102, 102]])

lut = vtk.vtkLookupTable()
lutNum = len(cl)
lut.SetNumberOfTableValues(lutNum)
lut.Build()
for ii,cc in enumerate(cl):
	lut.SetTableValue(ii,cc[0],cc[1],cc[2],1.0)
lut.SetRange(0,numCats-1)

chart.GetPlot(0).SetInput(table)
chart.GetPlot(0).SetScalarVisibility(1)
chart.GetPlot(0).SetLookupTable(lut)
chart.GetPlot(0).SelectColorArray("Category_ids")
# chart.GetAxis(0).GetPen().SetColor(0,0,0,50)
chart.GetPlot(0).GetPen().SetOpacityF(0.5)
chart.GetPlot(0).GetPen().SetWidth(2)

view.GetRenderWindow().SetMultiSamples(0)
view.GetRenderWindow().Render()

# Start interaction event loop
view.GetInteractor().Start()


On Oct 13, 2011, at 8:42 AM, HansAusBremen wrote:

> Hi again,
> 
> I want the each line of my 
> http://www.vtk.org/doc/nightly/html/classvtkChartParallelCoordinates.html
> vtkChartParallelCoordinates  to be colored in a specific color.
> Each object (represented through a spline of lines) gets its own color.
> For example: The Plot shows two cars in comparison. Car 1 and Car 2. Both
> have different values in some categories as horsepower, weight, max speed
> etc. I want the lines for car1 to be drawn in red and those for car2 in
> blue.
> 
> In this 
> http://vtk.org/gitweb?p=VTK.git;a=blob;f=Charts/Testing/Python/TestParallelCoordinatesColors.py
> test  a lookuptable is used. But as it maps colors to values I'm not quite
> sure if its the right approach to my problem.
> 
> Thanks in advance.
> 
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Set-the-Color-of-each-line-in-vtkChartParallelCoordinates-tp4899104p4899104.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list