How to color scatter plot points by the value of a third column in Paraview like gnuplot palette?
Asked Answered
T

1

1

For example, I generate the data with:

i=0; while [ "$i" -lt 10 ]; do echo "$i,$((2*i)),$((4*i))"; i=$((i+1)); done > main.csv

which contains:

0,0,0
1,2,4
2,4,8
3,6,12
4,8,16
5,10,20
6,12,24
7,14,28
8,16,32
9,18,36

Then for example in gnuplot, I get what I want with palette:

#!/usr/bin/env gnuplot
set terminal png size 1024,1024
set output "main.png"
set datafile separator ","
set key off
plot "main.csv" using 1:2:3 palette pt 7 pointsize 10

which gives the desired:

enter image description here

How to achieve this effect with Paraview?

I managed to make the scatter plot with a Line Chart View, but all points are red like this:

enter image description here

Also I could not resize the marker sizes, but for that I found an open issue: https://gitlab.kitware.com/paraview/paraview/issues/14169

I am initially learning the GUI for plotting, but if you have a scripting option that is good to know too.

The reason I am looking into Parasol is that I need to plot 10M points interactively, which I have found gnuplot and matplotlib not to handle well, so I'm curious if this VTK-based solution will cut it. More info at: Large plot: ~20 million samples, gigabytes of data

Tested in Ubuntu 18.10, Paraview 5.4.1.

Taxiway answered 1/5, 2019 at 7:57 Comment(3)
Hello. I think you cannot do that with the Line Chart View of ParaView. In fact, I think the best way to do that with ParaView is to use the Python View. However, imho, the Python View API is more complicated than that of other plotting tools. I would advise you to use something else, for instance matplotlib if you're OK with python scripting (see for instance here: #17682716)Spouse
Hi @BertrandGazanion I'm OK with scripting, and I know how to do this with Matplotlib. When I asked this, I was mostly interested in evaluating high performance plotting options, since Matplotlib could not handle the 10 million points I had as mentioned at: #5855015 :) GUI setup would be ideal mostly as part of my evaluation for others. If you can make your Paraview solution more precise, do post it as an answer.Taxiway
Hi @ciro. I didn't realize the performance issue, but know I understand why you want to use ParaView. I am not relevant on the Python View, but as far as I know it relies on matlplotlib. I can show you a solution using glyphs in a 3D render view, however.Spouse
S
1

Here is the python script to read the file and display the markers in the ParaView 3D Render View.

import paraview.simple as pvs

# create a new 'CSV Reader'
csvReader = pvs.CSVReader(FileName=['C:\\your_file.csv'])
csvReader.HaveHeaders = 0

# create a new 'Table To Points'
tableToPoints = pvs.TableToPoints(Input=csvReader)
tableToPoints.XColumn = 'Field 0'
tableToPoints.YColumn = 'Field 1'
tableToPoints.ZColumn = 'Field 2'
tableToPoints.KeepAllDataArrays = 1
tableToPoints.a2DPoints = 1

# create a new 'Glyph'
glyph = pvs.Glyph(Input=tableToPoints, GlyphType='Arrow')
glyph.Scalars = ['POINTS', 'Field 0']
glyph.Vectors = ['POINTS', 'None']
glyph.GlyphType = '2D Glyph'
glyph.GlyphType.GlyphType = 'Square'
glyph.GlyphType.Filled = 1
glyph.ScaleMode = 'off'
glyph.ScaleFactor = 1.0
glyph.GlyphMode = 'All Points'
### uncomment to scale markers by 'Field 2'
# glyph1.Scalars = ['POINTS', 'Field 2']
# glyph1.ScaleMode = 'scalar'

# show data in view
renderView = pvs.GetActiveView()
glyphDisplay = pvs.Show(glyph, renderView)
glyphDisplay.Representation = 'Surface'
pvs.ColorBy(glyphDisplay, ('POINTS', 'Field 2'))
glyphDisplay.SetScalarBarVisibility(renderView, True)
glyphDisplay.RescaleTransferFunctionToDataRange(True, False)

renderView.Update()
pvs.UpdatePipeline()
renderView.AxesGrid.Visibility = 1
renderView.ResetCamera()
pvs.Render(renderView)

And the result: enter image description here

Spouse answered 24/5, 2019 at 8:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.