Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [x] #334: Fix - No output visible on pcolormesh_demo.html (COMPLETED - PR #351)
- [x] #333: Fix - Circles seem not centered with line plot in marker_demo.html (COMPLETED)
- [x] #332: Fix - Dashed and dash-dotted look funny on line_styles.html (COMPLETED)
- [ ] #330: Fix - Old plot not cleared in second figure (figure() call) in contour_demo.html
- [x] #330: Fix - Old plot not cleared in second figure (figure() call) in contour_demo.html (COMPLETED)
- [ ] #329: Fix - No output visible on colored_contours.html
- [ ] #328: Fix - One legend entry too much in basic_plots.html second plot
- [ ] #327: Fix - MP4 link not showing on animation.html
Expand All @@ -24,6 +24,7 @@
- [ ] #350: Refactor - improve documentation comments in raster drawing module

## DOING (Current Work)
- [ ] #330: Fix - Old plot not cleared in second figure (figure() call) in contour_demo.html

## BLOCKED (Infrastructure Issues)

Expand Down
2 changes: 1 addition & 1 deletion src/fortplot_figure_core.f90
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ subroutine initialize(self, width, height, backend)

if (.not. allocated(self%plots)) then
allocate(self%plots(self%max_plots))
self%plot_count = 0 ! Only reset plot count when allocating plots array
end if
self%plot_count = 0 ! Reset plot count on every figure() call
self%rendered = .false.

! Preserve existing legend settings during re-initialization
Expand Down
38 changes: 38 additions & 0 deletions test/test_figure_clear_330.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
program test_figure_clear
!> Test case for Issue #330: Ensure figure() properly clears previous plots
!> This test validates that plot_count is reset when figure() is called multiple times

use fortplot
use iso_fortran_env, only: real64
implicit none

real(real64) :: x(5) = [1.0_real64, 2.0_real64, 3.0_real64, 4.0_real64, 5.0_real64]
real(real64) :: y1(5) = [1.0_real64, 4.0_real64, 2.0_real64, 3.0_real64, 5.0_real64]
real(real64) :: y2(5) = [2.0_real64, 3.0_real64, 1.0_real64, 5.0_real64, 4.0_real64]

print *, 'Testing figure clearing functionality...'

! First figure - should have 1 plot
call figure()
call plot(x, y1)
print *, 'First figure created with 1 plot'

! Second figure - should clear previous plot and have only 1 plot
call figure()
call plot(x, y2)
print *, 'Second figure created - previous plot should be cleared'

! Test with multiple plots in sequence
call figure()
call plot(x, y1, label='Line 1')
call plot(x, y2, label='Line 2')
print *, 'Third figure with 2 plots'

! Clear and add single plot again
call figure()
call plot(x, y1)
print *, 'Fourth figure - should have only 1 plot, not accumulating previous plots'

print *, 'Figure clearing test completed successfully'

end program test_figure_clear
Loading