Fix interactive eulerplot

This commit is contained in:
Magnus Ulimoen 2021-06-27 12:34:59 +02:00
parent 091076a9ad
commit 300f6a34e5
1 changed files with 24 additions and 23 deletions

View File

@ -204,41 +204,42 @@ def plot_pressure_slider(grids, save: bool, filename="figure.png"):
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
plt.colorbar(sm, cax=cbar_ax) plt.colorbar(sm, cax=cbar_ax)
plt.xlabel("x") ax.set_xlabel("x")
plt.ylabel("y") ax.set_ylabel("y")
itime = len(t) - 1 itime = len(t) - 1
slider = mpl.widgets.Slider( slider = mpl.widgets.Slider(
slider_ax, "itime", 0, itime, valinit=itime, valstep=1, valfmt="%0.0f" slider_ax, "itime", 0, itime, valinit=itime, valstep=1, valfmt="%0.0f"
) )
contours = [] class Updater(object):
def __init__(this):
this.contours = None
def update(itime): def update(this, itime):
global contours
contours = []
itime = int(itime) itime = int(itime)
for ct in contours:
for coll in ct.collections:
coll.remove()
for g in grids: for g in grids:
ct = ax.contourf( if this.contours is not None:
g["x"], for coll in this.contours.collections:
g["y"], coll.remove()
pressure( pres = pressure(
g["rho"][itime, :, :], g["rho"][itime, :, :],
g["rhou"][itime, :, :], g["rhou"][itime, :, :],
g["rhov"][itime, :, :], g["rhov"][itime, :, :],
g["e"][itime, :, :], g["e"][itime, :, :],
), )
this.contours = ax.contourf(
g["x"],
g["y"],
pres,
cmap=cmap, cmap=cmap,
levels=levels, levels=levels,
) )
contours.append(ct)
slider.valtext.set_text(t[itime]) slider.valtext.set_text(t[itime])
update(itime) up = Updater()
slider.on_changed(update) up.update(itime)
slider.on_changed(up.update)
plt.show() plt.show()