Fix interactive eulerplot
This commit is contained in:
parent
091076a9ad
commit
300f6a34e5
|
@ -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
|
itime = int(itime)
|
||||||
contours = []
|
for g in grids:
|
||||||
itime = int(itime)
|
if this.contours is not None:
|
||||||
for ct in contours:
|
for coll in this.contours.collections:
|
||||||
for coll in ct.collections:
|
coll.remove()
|
||||||
coll.remove()
|
pres = pressure(
|
||||||
for g in grids:
|
|
||||||
ct = ax.contourf(
|
|
||||||
g["x"],
|
|
||||||
g["y"],
|
|
||||||
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, :, :],
|
||||||
),
|
)
|
||||||
cmap=cmap,
|
this.contours = ax.contourf(
|
||||||
levels=levels,
|
g["x"],
|
||||||
)
|
g["y"],
|
||||||
contours.append(ct)
|
pres,
|
||||||
slider.valtext.set_text(t[itime])
|
cmap=cmap,
|
||||||
|
levels=levels,
|
||||||
|
)
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue