5.4 s

Plotting & visualization

Human perception is much better adapted to visual representation than to numbers

Purposes of plotting:

  • Visualization of research results for publications & presentations

  • Debugging + developing algorithms

  • "In-situ visualization" of evolving computations

  • Investigation of data

  • 1D, 2D, 3D, 4D data

  • Similar tasks in CAD, Gaming, Virtual Reality

11.0 μs

Processing steps in visualization

High level tasks:

  • Representation of data using elementary primitives: points,lines, triangles

  • Very different depending on purpose

Low level tasks

  • Coordinate transformation from "world coordinates" of a particular model to screen coordinates

  • Transformation 3D 2D, visibility computation

  • Coloring, lighting, transparency

  • Rasterization: turn smooth data into pixels

9.4 μs

Software implementation of low level tasks

  • Software: rendering libraries, e.g. Cairo, AGG

  • Software for vector based graphics formats, e.g. PDF, postscript, svg

  • Typically performed on CPU

5.3 μs

Hardware for low level tasks

  • Low level tasks are characterized by huge number of very similar operations

  • Well adaped to parallelism "Single Instruction, Multiple Data" (SIMD)

  • Dedicated hardware: Graphics Processing Unit (GPU) can free CPU from these taks

  • Multiple parallel pipelines, fast memory for intermediate results

(wikimedia)

27.0 ms

GPU Programming

  • Typically, GPUs are processing units which are connected via bus interface to CPU

  • GPU Programming:

    • Prepare low level data for GPU

    • Send data to GPU

    • Process data in rendering pipeline(s)

  • Modern visualization programs have a CPU part and GPU parts a.k.a. shaders

    • Shaders allow to program details of data processing on GPU

    • Compiled on CPU, sent along with data to GPU

  • Modern libraries: Vulkan, modern OpenGL/WebGL, DirectX

  • Possibility to "mis-use" GPU for numerical computations

10.8 μs

GPU Programming in the "old days"

  • "Fixed function pipeline" in OpenGL 1.1 fixed one particular set of shaders

  • Easy to program

 glClear()
 glBegin(GL_TRIANGLES)
 glVertex3d(1,2,3)
 glVertex3d(1,5,4)
 glVertex3d(3,9,15)
 glEnd()
 glSwapBuffers()
  • Not anymore: now everything works through shaders leading to highly complex programs

6.0 μs

Library interfaces to GPU useful for Scientific Visualization

  • vtk (backend of Paraview)

  • three.js (for WebGL in the browser)

  • Alternatively, work directly with OpenGL...

  • very few

    • Money seems to be in gaming, battlefield rendering

    • Problem regadless of julia, python, C++,

  • Common approach:

    • Write data into "vtk" files, use paraview for visualization.

21.0 μs

Graphics in Julia

  • Plots.jl General purpose plotting package with different backends

    • GPU support via default gr backend (based on "old" OpenGL)

  • Plotly.jl Interface to javascript library plotly.js

    • plots in the browser or electron window

    • also as backend for Plots.jl

    • some WebGL functionality

  • Makie.jl

    • GPU based plotting using modern OpenGL

    • good plot performance, some precompilation time

    • essentially still under development

  • WGLMakie.jl maps Makie API to three.js, can be used from the browser

  • WriteVTK.jl vtk file writer for files to be used with paraview - so this is not a plotting library.

  • PyPlot.jl: Interface to python/matplotlib

    • realization via PyCall.jl

    • also as backend for Plots.jl

15.1 μs

PyPlot

During this course we will use PyPlot, but feel free to try some of the other packages.

  • It has all the functionality we need (including plots on triangular meshes not available in Plots.jl)

  • Python users instantly will recognize the interfaces

  • Knowledge obtained here can also be used in python

  • Low precompilation time (as opposed to e.g. Makie)

Drawback: Plotting performance - it does not use the GPU, large parts of the logic are in python

6.7 μs
6.1 μs

We can choose the way the plot is created: in the browser it can make sense to create it as a vector graphic in svg format. The alternatice is png, a pixel based format.

2.3 μs
true
7.3 μs

How to create a plot ?

2.4 μs
21.4 ms

Instead of a begin/end block we used a let block. In a let block, all new variables are local and don't interfer with other pluto cells.

2.5 μs

This plot is not nice. It lacks:

  • orientation lines ("grid")

  • title

  • axis labels

  • label of the plot

  • size adjustment

6.6 μs
73.2 ms

We can use LATEX math strings in plot labels here, we just need to escape the $ symbols with \ !

2.7 μs
62.1 ms

Plotting 2D data

2.5 μs

k: l:

22.1 ms
94.7 ms
78.9 ms
207 ms

Remove the moire in the plot:

This occurs in contourf when we use many colors to make a smooth impression.

17.2 ms

α: β:

9.2 ms
193 ms

... all movements could be much faster if we would use the GPU...

2.4 μs

There are analogues for contour contourf and surf on triangular meshes which will be discussed once we get there in the course.

5.5 μs

Feel free watch my vizcon2 talk about using vtk from Julia - just to show what could be possible. Unfortunately, these things currently work only on Linux...

7.6 μs