Following a earlier question ( here ) I'd now like to just plot a point to every grid value which is significant. In the moment I do it like this
ax.contourf(x, y, z)
for i in x:
for j in y:
if significant[i, j]==True: ax.plot(i, j, 'bo')
which is obviousliy really bad as it is very slow. Is there some simple (fast) solution for this problem? Note that x and y don't have the same length and I need x to be of variable length.
You can do the loop only where significant is true:
for i, j in zip(*np.where(significant)):
ax.plot(i, j, 'bo')
Or, if x and y are not arange-like:
for i, j in zip(*np.where(significant)):
ax.plot(x[i], y[j], 'bo')
np.where will return a tuple with two elements, the first and the second index of the nonzero elements.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.