2021年4月10日星期六

how to change pcolor one grid color on click in matplotlib?

i'm new to python and matplotlib, i want to change grid color on click, but following code can't, how to do it? enter image description here

#!/usr/bin/python  import matplotlib.pyplot as plt  import numpy as np  from matplotlib.colors import LogNorm  import math         Z = np.random.rand(25, 25)    Z = []  for x in range(25) :      sublist = [1]*25      Z.append(sublist)      fig, ax = plt.subplots()    Z[0][0] = 0  mesh = ax.pcolor(Z,edgecolor= 'k')    def onclick(event):      print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %            ('double' if event.dblclick else 'single', event.button,             event.x, event.y, event.xdata, event.ydata))      _gx = int(math.floor(event.xdata))      _gy = int(math.floor(event.ydata))      print("index x=%d y=%d", _gx,_gy)      Z[_gy][_gx] = 25      ax.pcolor(Z)    cid = fig.canvas.mpl_connect('button_press_event', onclick)    plt.title('matplotlib.pyplot.pcolormesh() function Example', fontweight ="bold")  plt.show()  
https://stackoverflow.com/questions/67041088/how-to-change-pcolor-one-grid-color-on-click-in-matplotlib April 11, 2021 at 11:05AM

没有评论:

发表评论