简体   繁体   English

使用 CSV 绘制平行坐标

[英]Using CSV to plot parallel coordinates

I am trying to plot a parallel coordinates graph using data froma csv file.我正在尝试使用来自 csv 文件的数据绘制平行坐标图。 The csv file contains four columns. csv 文件包含四列。 An example of the data is:数据的一个例子是:

A, B, C, D
1, 2, 4, 8
5, 6, 1, 5
6, 5, 5, 10

I am getting an error that No valid input arrays specified .我收到错误No valid input arrays specified I do not know what I am doing wrong.我不知道我做错了什么。 Here is the code I have so far.这是我到目前为止的代码。

from vtk import *
import csv

FILENAME_PARA_COORD = "htc_2.csv"

# Load the paracoordinates table from CSV file
csv_source = vtkDelimitedTextReader()
csv_source.SetFieldDelimiterCharacters(",")
csv_source.DetectNumericColumnsOn()
csv_source.SetHaveHeaders(True)
csv_source.SetFileName(FILENAME_PARA_COORD)

# Set up the parallel coordinates Representation to be used in this view
rep = vtk.vtkParallelCoordinatesRepresentation()

# Plug your reader in here for your own data
if vtk.VTK_MAJOR_VERSION <= 5:
   rep.SetInput(csv_source.GetOutput())

else:
   rep.SetInputConnection(csv_source.GetOutputPort())

# List all of the attribute arrays you want plotted in parallel coordinates
rep.SetInputArrayToProcess(0, 0, 0, 0, 'A')
rep.SetInputArrayToProcess(1, 0, 0, 0, 'B')
rep.SetInputArrayToProcess(2, 0, 0, 0, 'C')
rep.SetInputArrayToProcess(3, 0, 0, 0, 'D')

rep.SetUseCurves(0) # set to 1 to use smooth curves
rep.SetLineOpacity(0.5)

#Set up the Parallel Coordinates View and hook in the Representation
view = vtk.vtkParallelCoordinatesView()
view.SetRepresentation(rep)

# Inspect Mode determines whether your interactions manipulate the axes or
# select data
view.SetInspectMode(1) # VTK_INSPECT_SELECT_DATA =1

# Brush Mode determines the type of interaction you perform to select data
view.SetBrushModeToLasso()


# Brush Operator determines how each new selection interaction changes
# selected lines

view.SetBrushOperatorToReplace()

def ToggleInspectors(obj, event):
    # Define the callback routine which toggles between "Inspect Modes"
    if (view.GetInspectMode() == 0):
        view.SetInspectMode(1)
    else:
        view.SetInpsectMode(0)

# Hook up the callback to togle between inspect modes
# (manip axes & select data)
view.GetInteractor().AddObserver("UserEvent", ToggleInspectors)

# Set up render window
view.GetRenderWindow().SetSize(600, 300)
view.ResetCamera()
view.Render()

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

One way is to create lists for each column and then convert it into an array and plot:一种方法是为每一列创建列表,然后将其转换为数组并绘制:

Eg:例如:

A = ['1','2','3','4']     #list of strings
A = [int(i) for i in A]   #to 
O/p A = [1,2,3,4]         #list of integers

Then you can plot parallel coordinates.然后你可以绘制平行坐标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM