The problem I'm facing is that I'm unable to figure out how to update the figure when I increase/decrease values with my slider.
I am creating an x, y mesh grid, then plotting it, and updating the values within my array to define a new mesh. I would like to be able to move the slider and see a finer/coarser grid and update the plot and axes.
Additionally, I would like the user to be able to move the grid lines interactively with the mouse. This is not included in example code. Does someone know how to implement this?
There are similar questions that have been asked about updating values on a plot with a slider, but perhaps none address this specific problem; can someone help me figure out what I'm doing wrong? I realize I don't have anything that is redrawing the plot (though I have tested various things), but am unsure how to implement this, as M.plotGrid() creates the grid, so it may/may not be as easy as using fig.canvas.draw_idle().
Here is my code:
#Create simple evenly spaced mesh and allow slider to change values
from SimPEG import Mesh, np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons
hx = np.r_[0.1,0.1,0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
hy = np.r_[0.1,0.1,0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
M = Mesh.TensorMesh([hx, hy])
M.plotGrid()
#Define slider location, size, and color for adjusting mesh values
axhx = plt.axes([0.25, 0.1, 0.65, 0.03])
axhy = plt.axes([0.25, 0.15, 0.65, 0.03])
xnode_inc = Slider(axhx, 'X mesh Node', 0.1, 1000.0, valinit=0)
anode_inc = Slider(axhy, 'Y mesh Node', 0.1, 1000.0, valinit=0)
def update(val):
framehx = xnode_inc.val + hx
framehy = ynode_inc.val + hy
M = Mesh.TensorMesh([framehx, framehy])
print M, framehx, framehy
M.plotGrid()
xnode_inc.on_changed(update)
ynode_inc.on_changed(update)
plt.show()