@@ -410,3 +410,59 @@ def test_contour_closed_line_loop():
410410 ax .contour (z , [0.5 ], linewidths = [20 ], alpha = 0.7 )
411411 ax .set_xlim (- 0.1 , 2.1 )
412412 ax .set_ylim (- 0.1 , 3.1 )
413+
414+
415+ def test_quadcontourset_reuse ():
416+ # If QuadContourSet returned from one contour(f) call is passed as first
417+ # argument to another the underlying C++ contour generator will be reused.
418+ x , y = np .meshgrid ([0.0 , 1.0 ], [0.0 , 1.0 ])
419+ z = x + y
420+ fig , ax = plt .subplots ()
421+ qcs1 = ax .contourf (x , y , z )
422+ qcs2 = ax .contour (x , y , z )
423+ assert qcs2 ._contour_generator != qcs1 ._contour_generator
424+ qcs3 = ax .contour (qcs1 , z )
425+ assert qcs3 ._contour_generator == qcs1 ._contour_generator
426+
427+
428+ @image_comparison (baseline_images = ['contour_manual' ],
429+ extensions = ['png' ], remove_text = True )
430+ def test_contour_manual ():
431+ # Manually specifying contour lines/polygons to plot.
432+ from matplotlib .contour import ContourSet
433+
434+ fig , ax = plt .subplots (figsize = (4 , 4 ))
435+ cmap = 'viridis'
436+
437+ # Segments only (no 'kind' codes).
438+ lines0 = [[[2 , 0 ], [1 , 2 ], [1 , 3 ]]] # Single line.
439+ lines1 = [[[3 , 0 ], [3 , 2 ]], [[3 , 3 ], [3 , 4 ]]] # Two lines.
440+ filled01 = [[[0 , 0 ], [0 , 4 ], [1 , 3 ], [1 , 2 ], [2 , 0 ]]]
441+ filled12 = [[[2 , 0 ], [3 , 0 ], [3 , 2 ], [1 , 3 ], [1 , 2 ]], # Two polygons.
442+ [[1 , 4 ], [3 , 4 ], [3 , 3 ]]]
443+ ContourSet (ax , [0 , 1 , 2 ], [filled01 , filled12 ], filled = True , cmap = cmap )
444+ ContourSet (ax , [1 , 2 ], [lines0 , lines1 ], linewidths = 3 , colors = ['r' , 'k' ])
445+
446+ # Segments and kind codes (1 = MOVETO, 2 = LINETO, 79 = CLOSEPOLY).
447+ segs = [[[4 , 0 ], [7 , 0 ], [7 , 3 ], [4 , 3 ], [4 , 0 ],
448+ [5 , 1 ], [5 , 2 ], [6 , 2 ], [6 , 1 ], [5 , 1 ]]]
449+ kinds = [[1 , 2 , 2 , 2 , 79 , 1 , 2 , 2 , 2 , 79 ]] # Polygon containing hole.
450+ ContourSet (ax , [2 , 3 ], [segs ], [kinds ], filled = True , cmap = cmap )
451+ ContourSet (ax , [2 ], [segs ], [kinds ], colors = 'k' , linewidths = 3 )
452+
453+
454+ @image_comparison (baseline_images = ['contour_line_start_on_corner_edge' ],
455+ extensions = ['png' ], remove_text = True )
456+ def test_contour_line_start_on_corner_edge ():
457+ fig , ax = plt .subplots (figsize = (6 , 5 ))
458+
459+ x , y = np .meshgrid ([0 , 1 , 2 , 3 , 4 ], [0 , 1 , 2 ])
460+ z = 1.2 - (x - 2 )** 2 + (y - 1 )** 2
461+ mask = np .zeros_like (z , dtype = bool )
462+ mask [1 , 1 ] = mask [1 , 3 ] = True
463+ z = np .ma .array (z , mask = mask )
464+
465+ filled = ax .contourf (x , y , z , corner_mask = True )
466+ cbar = fig .colorbar (filled )
467+ lines = ax .contour (x , y , z , corner_mask = True , colors = 'k' )
468+ cbar .add_lines (lines )
0 commit comments