Skip to content

Conversation

@krystophny
Copy link
Collaborator

Summary

Changes

  • Fixed initialize() method in src/fortplot_figure_core.f90 to reset plot_count unconditionally
  • Added test case test/test_figure_clear_330.f90 to validate proper figure clearing behavior
  • Preserves allocation logic - plots array is still only allocated once for efficiency

Test Plan

  • Created focused test case for figure clearing functionality
  • Verified test passes with fix applied
  • Ran contour_demo to confirm no more overlapping contours
  • Ran related figure tests to ensure no regressions
  • All tests pass successfully

Technical Details

Before Fix:

if (.not. allocated(self%plots)) then
    allocate(self%plots(self%max_plots))
    self%plot_count = 0  ! Only reset when allocating
end if

After Fix:

if (.not. allocated(self%plots)) then
    allocate(self%plots(self%max_plots))
end if
self%plot_count = 0  ! Reset on every figure() call

Expected Behavior After Fix:

  1. First figure() call → allocates plots array and sets plot_count = 0
  2. Add plots → plot_count increases normally
  3. Second figure() call → resets plot_count = 0 (plots array already allocated)
  4. Add new plots → start from index 0, replacing previous plots

This ensures proper plot isolation between figure() calls and resolves the overlapping contours issue.

fixes #330

- Move plot_count reset outside allocation check in initialize() method
- Fix issue where subsequent figure() calls didn't clear previous plots
- Add test case to validate proper figure clearing behavior
- Resolves overlapping contours issue in contour_demo.html

fixes #330
@codecov
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/fortplot_figure_core.f90 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@krystophny krystophny merged commit deb2ec3 into main Aug 25, 2025
5 checks passed
@krystophny krystophny deleted the fix-figure-clear-330 branch August 25, 2025 18:37
krystophny added a commit that referenced this pull request Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Old plot not cleared in second figure ... figure() call? https://lazy-fortran.github.io/fortplot/page/examples/contour_demo.html

2 participants