1

I would like to do a surface plot of a function f(x,y) that is defined for any integers x and y. The caveat is that I want to restrict the domain of (x,y) to a convex but non-rectangular region. (For example, I want to restrict to x>=0, y>=0, x+y<=b for some known integer b.)

I have been able to follow the matplotlib surface plotting examples, however all of these examples impose a rectangular domain. If you have any suggestions on how to accomplish this, they would be greatly appreciated.

Thank you in advance for your help.

user3890260
  • 101
  • 1
  • 1
  • 4
  • 1
    What is required for a matplotlib 3D `plot_surface` is a rectilinear grid, not a rectangular domain, see e.g. the surface of a sphere, which is not rectangular at all. I see two options, use a grid which only contains the desired values (x+y<=b) or mask a rectangular grid by the condition. – ImportanceOfBeingErnest Feb 08 '18 at 00:27
  • Oh, sorry, if x and y can only be integers, you cannot squeeze the grid, hence only the second option is possible. But, a third option would be to plot a `trisurf` plot, which does not have this restriction at all. – ImportanceOfBeingErnest Feb 08 '18 at 00:29
  • @ImportanceOfBeingErnest, would you mind elaborating on "or mask a rectangular grid by the condition." I'm not quite sure I know what that means. Thank you! – user3890260 Feb 08 '18 at 00:40
  • numpy provides masked arrays. Seems like [this is not working](https://stackoverflow.com/questions/24577248/how-to-make-a-3d-matlibplot-not-show-masked-values) though. So, it now depends on whether you need a colormap or not, using `nan`s would prevent a colormap from being used. Should we close this as duplicate? – ImportanceOfBeingErnest Feb 08 '18 at 00:52

0 Answers0