Representation of 3D polytope in 2D

Viewed 133


I am struggling with polytope representation.
I have a set of vertices (in 3D) defining a convex polytope. And I want to plot it.
I can easily represent the whole polytope in 3D or its projection in 2D. But I cannot find a packages (in R or Python) to represent it in 2D with the third component represented by a color on the plot.
For instance, if I have such a set of vertices :

array([[0., 0., 0.],
       [1., 0., 0.],
       [0., 1., 0.],
       [1., 1., 0.],
       [0., 0., 1.],
       [1., 0., 1.]])

In 3D you get : Polytop plot generated by plotly

And What I would like to have is the upper envelop in the Z axis which should look like something like this: Contour plot generated with plotly

(minus the contours of course...). If you have any idea how to solve this representation issue I am all ears!
Thanks

1 Answers

First, reshape the array and then use your favourite package to plot, eg. seaborn or matplotlib:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

m = [[0., 0., 0.],
     [1., 0., 0.],
     [0., 1., 0.],
     [1., 1., 0.],
     [0., 0., 1.],
     [1., 0., 1.]]

data = np.asarray(m).reshape(3,6)[::-1]
sns.heatmap(data, cmap = 'jet')
#plt.imshow(data)
plt.xlabel('level 1')
plt.ylabel('level 2')

enter image description here

Maybe this can help!

Related