Search code examples
pythongraphplotlylinear-programming

Is there a way to visualize the feasible region for a set of linear inequalities in plotly in 2d? in 3d?


Is there a way to visualize the feasible region for a set of linear inequalities in plotly in 2d? in 3d?

Say I have the inequalities:

enter image description here

How can I visualize the feasible region in Plotly? What about if my region is in 3d? I know that we can do this in other libraries (e.g. matplotlib), but I specifically want to do this in plotly.


Solution

  • Unfortunately, I don't think so.

    A few months ago I stumbled on the same problem as I was developing a new plotting module for SymPy. After testing different things, these are my conclusions:

    • Matplotlib offers at least two ways to achieve that: either with ax.contour (and setting the contour levels) or with ax.fill.
    • Plotly's go.Contour doesn't currently support setting contour levels (see issue 4503). This results in difficult to read plots. Here is a comparison of the first inequality that you posted with Matplotlib (blue region is where the inequality is true) and Plotly (yellow region is where the inequality is true).

    enter image description here enter image description here

    • Plotly doesn't implement a feature similar to ax.fill.
    • Plotly exposes the go.Heatmap, but it is not suitable for this application.