0

I have an array of x and y with several functions evaluated at each point. I'd like to make a diagram that shows in which region each function is the greatest of all of them. I naturally tried assigning an integer index to each point, with the index corresponding to which function is greatest, then plotting contours with levels between the integer values, but this isn't particularly pretty. Is there a better way?

Similar questions have been asked before. e.g. this or this, but the answers are only has good as what I demonstrate below. But I'm ready to accept that's the best one can do without a much more complicated approach.

As a simple example, here's a case that has three regions in the unit square.

import numpy as np
import matplotlib.pyplot as pl

x, y = np.ogrid[0:1:101j,0:1:126j]

z = 0*x*y
z[y>1-x] = 1
z[y>x] = 2

pl.contour(x[:,0], y[0,:], z.T, levels=[0.5, 1.5], vmax=np.inf, alpha=0.5)

which gives

Contours separating three qualitative regions in the unit square.

where the ideal would be more like:

Ideal solution

In particular, I'm trying to avoid the doubled up line from (0,0) to (0.5,0.5), or at least the small gap between the two contours (which I've forced to the same colour with vmax=np.inf).

Warrick
  • 667
  • 10
  • 18
  • See also https://stackoverflow.com/questions/59742788/how-to-make-a-contour-plot-with-three-variables-in-a-dataset – JohanC Oct 04 '21 at 15:37

0 Answers0