u-anurag / OpenSeesPy

OpenSeesPy-Visualization: This branch is to work on Plotting commands to Python-based visualization of OpenSees models.
https://openseespydoc.readthedocs.io/en/latest/src/Plotting_Development_Guide.html
5 stars 2 forks source link

Click Events #34

Open cslotboom opened 4 years ago

cslotboom commented 4 years ago

I thought this matplotlib example was something we could potentially integrate into future functions:

We can potentially use click events to show data, some examples might be:

Just wanted to raise it for discussion.

u-anurag commented 4 years ago

This is good.

cslotboom commented 4 years ago

In #77 I begin work on this. It's better to discuss some things here. The your biggest comment was reusing the plot_model_deformation(). I think this is ideal, but there are a few challenges.

The main problem is with the "_plot_on_click" function, which needs to know about DeflectedNodeCoordArray. I don't know how to pass this variable to the function because it is a matplotlib event.

def _plot_on_click(self, event):

    timeSteps = self.timeSteps
    Disp_nodeArray =  self.Disp_nodeArray

    # Find the Node ID
    ind = event.ind[0]
    fig, ax = plt.subplots()
    line = ax.plot(timeSteps, self.scale*Disp_nodeArray[:,ind,0])
    ax.set_xlabel('time (s)')
    ax.set_ylabel('Displacement')

There are a few ways around this, i.e. global variables. However, generally using a class would work best.

It might be possible for us to call the existing plot function in our class, but that might require some shuffling around. We need to call fig.canvas.mpl_connect on the figure, before the plt.show(). Right now plt.show() is hard coded into the plot_model_defomration() function.

fig.canvas.mpl_connect('pick_event', self._plot_on_click)
plt.show()