Andrea Zonca Andrea Zonca - 4 years ago 231
Python Question

matplotlib contourf: get Z value under cursor

When I plot something with

contourf
, I see at the bottom of the plot window the current x and y values under the mouse cursor.
Is there a way to see also the z value?

Here an example
contourf
:

import matplotlib.pyplot as plt
import numpy as hp
plt.contourf(np.arange(16).reshape(-1,4))

Answer Source

The documentation example shows how you can insert z-value labels into your plot

Script: http://matplotlib.sourceforge.net/mpl_examples/pylab_examples/contour_demo.py

Basically, it's

plt.figure()
CS = plt.contour(X, Y, Z) 
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download