How to get the value of a cell in pcolormesh

Hi everyone!
It is cool to use the pcolormesh in matplotlib. However, is there a way to
get the i, j indexes of the clicked cell? I have try event.mouseevent.xdata
and event.mouseevent.x. But they did not return the index I need.

Thanks in advanced for your help.

Dr. Jiacong Huang
Nanjing Institute of Geography & Limnology
Chinese Academy of Sciences
73 East Beijing Road, Nanjing 210008, China
Tel./Fax: +86-25-86882127
Homepage: http://www.escience.cn/people/elake/index.html

---Code to generate pcolormesh-------------------------------
import numpy as np
from matplotlib.pyplot import figure, show
from numpy import ma

n = 12
x = np.linspace(-1.5,1.5,n)
y = np.linspace(-1.5,1.5,n*2)
X,Y = np.meshgrid(x,y);
Qx = np.cos(Y) - np.cos(X)
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.sqrt(X**2 + Y**2)/5;
Z = (Z - Z.min()) / (Z.max() - Z.min())

# The color array can include masked values:
Zm = ma.masked_where(np.fabs(Z) > 100, Z)

fig = figure()
ax = fig.add_subplot(111)
col = ax.pcolormesh(Qx[:5,:4],Qz[:5,:4],Zm[:4,:3])
show()

···

-------------------------

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/How-to-get-the-value-of-a-cell-in-pcolormesh-tp45499.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

To get the index of the grid you clicked on requires some knowledge of what artist you are working with.

See https://github.com/matplotlib/matplotlib/pull/3989 for some brand new code which makes this easier to implement in a general way.

While we catch up with that you will need to implement your own mapping of x/y in data space -> i, j See http://matplotlib.org/examples/api/image_zcoord.html for an example.

Tom

···

On Tue, May 12, 2015 at 2:21 AM GoogleWind <googlewind@…1221…> wrote:

Hi everyone!

It is cool to use the pcolormesh in matplotlib. However, is there a way to

get the i, j indexes of the clicked cell? I have try event.mouseevent.xdata

and event.mouseevent.x. But they did not return the index I need.

Thanks in advanced for your help.

Dr. Jiacong Huang

Nanjing Institute of Geography & Limnology

Chinese Academy of Sciences

73 East Beijing Road, Nanjing 210008, China

Tel./Fax: +86-25-86882127

Homepage: http://www.escience.cn/people/elake/index.html

—Code to generate pcolormesh-------------------------------

import numpy as np

from matplotlib.pyplot import figure, show

from numpy import ma

n = 12

x = np.linspace(-1.5,1.5,n)

y = np.linspace(-1.5,1.5,n*2)

X,Y = np.meshgrid(x,y);

Qx = np.cos(Y) - np.cos(X)

Qz = np.sin(Y) + np.sin(X)

Qx = (Qx + 1.1)

Z = np.sqrt(X2 + Y2)/5;

Z = (Z - Z.min()) / (Z.max() - Z.min())

The color array can include masked values:

Zm = ma.masked_where(np.fabs(Z) > 100, Z)

fig = figure()

ax = fig.add_subplot(111)

col = ax.pcolormesh(Qx[:5,:4],Qz[:5,:4],Zm[:4,:3])

show()


View this message in context: http://matplotlib.1069221.n5.nabble.com/How-to-get-the-value-of-a-cell-in-pcolormesh-tp45499.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


One dashboard for servers and applications across Physical-Virtual-Cloud

Widest out-of-the-box monitoring support with 50+ applications

Performance metrics, stats and reports that give you Actionable Insights

Deep dive visibility with transaction tracing using APM Insight.

http://ad.doubleclick.net/ddm/clk/290420510;117567292;y


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Tom,

It is nice to receive your hints. I would like to try it.

Best regards,
Jiacong Huang

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/How-to-get-the-value-of-a-cell-in-pcolormesh-tp45499p45610.html
Sent from the matplotlib - users mailing list archive at Nabble.com.