2

Someone posted how to convert 2D Matplotlib images to a np.array. I'd like to do the same for a 3D Matplotlib plot. To be clear, I am not asking to save a 2D "screenshot" of fig.canvas as an array, but rather a raster of the 3D lines as an array.

Why? My raw data is a list of node id's, their (x,y,z) coordinates, the node id's they are connected to, and the radius of those connections. I used mplot3d to connect these dots with lines, and now I want to use these 3D structures for machine vision research. For that, the data needs to be in a numpy array. I want to avoid writing a function to connect the nodes when a tool already exists.

crypdick
  • 16,152
  • 7
  • 51
  • 74
  • The best solution I can find so far is to render the arrays manually [using Bresenham's algorithm](https://stackoverflow.com/a/33468447/4212158) – crypdick Jul 11 '18 at 00:41
  • 1
    I did a bit of googling and found [this SO answer](https://stackoverflow.com/a/3151976/2454357) (maybe slight overkill), [this GitHup project](https://github.com/mdickinson/polyhedron), and [a Polyhedron class in SymPy](http://docs.sympy.org/latest/modules/combinatorics/polyhedron.html). Maybe you could utilise one of these to produce a 3d array of 'inside/outside pixels. – Thomas Kühn Jul 11 '18 at 07:10
  • Thanks Thomas, but I'm not clear how polyhedrons will help me since cylinders are not polyhedra. – crypdick Jul 11 '18 at 18:11
  • I wonder if [Blender](https://www.blender.org/)'s Python interface might be helpful here, e.g. https://blender.stackexchange.com/questions/5898/how-can-i-create-a-cylinder-linking-two-points-with-python – Oliver Evans Jul 11 '18 at 18:14
  • @crypdick I missed the cylinder part. However, you can always approximate a cylinder with a polyhedron (the same way you can approximate a circle with a regular polygon -- just use enough edges). Could you maybe post a screenshot of your `mplot3d` code to give us a better idea what you're after? – Thomas Kühn Jul 11 '18 at 18:26
  • I meant a screenshot of the result of the code :) – Thomas Kühn Jul 11 '18 at 18:58
  • Thomas, I suspect that's a no-go due to performance considerations (I'm dealing w petabytes of data). This is not the best example but it's what I have on hand: https://youtu.be/m8Q1_gMwbGw This is an extremely zoomed in segment of one 3D structure. On the larger scale, the trajectories are composed of connected nodes, trajectories have many forks/branchs, and there is a fair amount of variability in line thickness. – crypdick Jul 11 '18 at 21:39

0 Answers0