0

Hello i want to create a highlighting on a set of values in a 3D plot(pcolor). I didn't find anything on stackoverflow. In In a matplotlib plot, can I highlight specific x-value ranges? there is a example how to do it on a 2D plot. There they using axvspan this works for rectangular higlighting too but not for othershapes. The closed i can get to what i need is this...

import numpy as np
import matplotlib.pyplot as plt

arr0 = np.arange(40)
arr1 = np.arange(20)
arr1lim = 12

a, b = np.meshgrid(np.arange(-20, 20), np.arange(-20, 20))
xyrange = a + b
xyrange = xyrange[:, 5: 25]

range0 = np.where(arr1 <= arr1lim)
range1 = np.where(xyrange >= 0)

overlay = np.zeros_like(xyrange, dtype=np.float)
overlay[range1[0], range1[1]] = 1
overlay[:, range0[0][-1]: -1] = 0
overlay[np.where(overlay == 0)] = None

fig = plt.figure()
ax = fig.add_subplot(111)
X, Y = np.meshgrid(arr1, arr0)
workplot = ax.pcolor(X, Y, xyrange)
ax.pcolor(X, Y, overlay, linewidths=0, alpha=0.4, edgecolor=None)

result from script above

but it looks not as nice as with axvspan. Some difficulties i have are:

  • Adding color='red' option don't change the result.
  • the way it shows edges is ugly is isn't a smooth surface

So are there solution(s) for better higlighting?

Jan-Bert
  • 921
  • 4
  • 13
  • 22
  • The problem with overlaying a plot in a colored 2D plot is that you inevitably will lose information about the original data (it distorts the colors). Perhaps you could try the solution given in [this question](https://stackoverflow.com/q/56654952/8345628), where `imshow` is used instead of `pcolor` by the way (it is faster and prettier - it allows interpolation :P). – Lith Nov 27 '20 at 19:10
  • I agree with you about the lose of information, but for me it is not important it is a graphical representation of my ‘solution’ area. What to me more is a problem but `imshow` ignore axis input. At leas as far as looked at it (https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.imshow.html). Combining both types don’t work either since the `imshow` is below the `pcolor`. – Jan-Bert Dec 01 '20 at 09:48
  • You can use the `extent` argument of the `imshow` function to set the axis limits, though you are right in the sense that `imshow` only works for regularly spaced data. – Lith Dec 01 '20 at 18:52

0 Answers0