From e9e59a9dbb1bf5e361f6935e45eff1f4e21da5b9 Mon Sep 17 00:00:00 2001 From: Lagarrigue Patrick Date: Thu, 4 Jul 2024 15:28:50 +0200 Subject: [PATCH 1/2] changing update_plot --- psydac/api/tests/test_api_feec_2d.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/psydac/api/tests/test_api_feec_2d.py b/psydac/api/tests/test_api_feec_2d.py index 59d4b9834..41acbca34 100644 --- a/psydac/api/tests/test_api_feec_2d.py +++ b/psydac/api/tests/test_api_feec_2d.py @@ -170,13 +170,34 @@ def plot_field_and_error(name, x, y, field_h, field_ex, *gridlines): def update_plot(fig, t, x, y, field_h, field_ex): ax0, ax1, cax0, cax1 = fig.axes - ax0.collections.clear(); cax0.clear() - ax1.collections.clear(); cax1.clear() + + # Remove collections from ax0 + while ax0.collections: + ax0.collections[0].remove() + + # Remove collections from ax1 + while ax1.collections: + ax1.collections[0].remove() + + # Clear colorbars + while cax0.collections: + cax0.collections[0].remove() + + while cax1.collections: + cax1.collections[0].remove() + + # Create new contour plots im0 = ax0.contourf(x, y, field_h) im1 = ax1.contourf(x, y, field_ex - field_h) + + # Create new colorbars fig.colorbar(im0, cax=cax0) fig.colorbar(im1, cax=cax1) + + # Update the title fig.suptitle('Time t = {:10.3e}'.format(t)) + + # Draw the updated plot fig.canvas.draw() #============================================================================== From c4769abe66b51e39099d2b94f8cb8912b0f24007 Mon Sep 17 00:00:00 2001 From: Lagarrigue Patrick Date: Thu, 4 Jul 2024 16:09:15 +0200 Subject: [PATCH 2/2] ready for PR --- psydac/api/tests/test_api_feec_2d.py | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/psydac/api/tests/test_api_feec_2d.py b/psydac/api/tests/test_api_feec_2d.py index 41acbca34..91736cb8b 100644 --- a/psydac/api/tests/test_api_feec_2d.py +++ b/psydac/api/tests/test_api_feec_2d.py @@ -170,34 +170,13 @@ def plot_field_and_error(name, x, y, field_h, field_ex, *gridlines): def update_plot(fig, t, x, y, field_h, field_ex): ax0, ax1, cax0, cax1 = fig.axes - - # Remove collections from ax0 - while ax0.collections: - ax0.collections[0].remove() - - # Remove collections from ax1 - while ax1.collections: - ax1.collections[0].remove() - - # Clear colorbars - while cax0.collections: - cax0.collections[0].remove() - - while cax1.collections: - cax1.collections[0].remove() - - # Create new contour plots + ax0.collections[0].remove(); ax1.collections[0].remove() + cax0.collections[0].remove(); cax1.collections[0].remove() im0 = ax0.contourf(x, y, field_h) im1 = ax1.contourf(x, y, field_ex - field_h) - - # Create new colorbars fig.colorbar(im0, cax=cax0) fig.colorbar(im1, cax=cax1) - - # Update the title fig.suptitle('Time t = {:10.3e}'.format(t)) - - # Draw the updated plot fig.canvas.draw() #==============================================================================