Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a crosshair or marker to a matplotlib contour plot

I'm plotting a NumPy array as a contour plot using matplotlib:

import numpy as np
import matplotlib.pyplot as plt

plt.contour(array, linewidths = 1, colors = 'k')
plt.contourf(array, cmap = plt.cm.jet)
plt.colorbar()
plt.show()

I would like to add a 'crosshair' or another marker to denote the maximum value in the array which is given by:

maxi = np.max(array)

How should I go about doing this?

like image 546
El Confuso Avatar asked Feb 13 '23 01:02

El Confuso


1 Answers

You can simply plot the cross if you know the position.

[row, col] = numpy.where(array==np.max(array))
plt.plot(col, row, 'b+')

To change the markersize check this.

like image 53
zinjaai Avatar answered Feb 14 '23 19:02

zinjaai