@@ -360,6 +360,8 @@ def box_to_Rectangle(self, box):
360360 return Rectangle (box .lower , * box .shape )
361361
362362 def plot_2d_patches (self , ilvl , collections , ** kwargs ):
363+ from matplotlib .patches import Rectangle
364+
363365 if isinstance (collections , list ) and all (
364366 [isinstance (el , Box ) for el in collections ]
365367 ):
@@ -370,35 +372,47 @@ def plot_2d_patches(self, ilvl, collections, **kwargs):
370372 level_domain_box = self .level_domain_box (ilvl )
371373 mi , ma = level_domain_box .lower .min (), level_domain_box .upper .max ()
372374
373- fig , ax = kwargs .get ("subplot" , plt .subplots (figsize = (6 , 6 )))
375+ fig , ax = kwargs .get ("subplot" , plt .subplots (figsize = (16 , 16 )))
376+
377+ i0 , j0 = level_domain_box .lower
378+ i1 , j1 = level_domain_box .upper
379+ ij = np .zeros ((i1 - i0 + 1 , j1 - j0 + 1 )) + np .nan
380+ ix = np .arange (i0 , i1 + 1 )
381+ iy = np .arange (j0 , j1 + 1 )
374382
375383 for collection in collections :
376- facecolor = collection .get ("facecolor" , "none" )
377- edgecolor = collection .get ("edgecolor" , "purple" )
378- alpha = collection .get ("alpha" , 1 )
379- rects = [self .box_to_Rectangle (box ) for box in collection ["boxes" ]]
380-
381- ax .add_collection (
382- PatchCollection (
383- rects , facecolor = facecolor , alpha = alpha , edgecolor = edgecolor
384- )
385- )
384+ value = collection .get ("value" , np .nan )
385+ for box in collection ["boxes" ]:
386+ i0 , j0 = box .lower
387+ i1 , j1 = box .upper
388+ ij [i0 : i1 + 1 , j0 : j1 + 1 ] = value
389+ if "coords" in collection :
390+ for coords in collection ["coords" ]:
391+ ij [coords ] = collection ["value" ]
392+
393+ ax .pcolormesh (ix , iy , ij .T , edgecolors = "k" , cmap = "jet" )
394+ ax .set_xticks (ix )
395+ ax .set_yticks (iy )
396+
397+ for patch in self .level (ilvl ).patches :
398+ box = patch .box
399+ r = Rectangle (box .lower - 0.5 , * (box .upper + 0.5 ))
400+
401+ r .set_edgecolor ("r" )
402+ r .set_facecolor ("none" )
403+ r .set_linewidth (2 )
404+ ax .add_patch (r )
386405
387406 if "title" in kwargs :
388407 from textwrap import wrap
389408
390409 xfigsize = int (fig .get_size_inches ()[0 ] * 10 ) # 10 characters per inch
391410 ax .set_title ("\n " .join (wrap (kwargs ["title" ], xfigsize )))
392411
393- major_ticks = np .arange (mi - 5 , ma + 5 + 5 , 5 )
394- ax .set_xticks (major_ticks )
395- ax .set_yticks (major_ticks )
396-
397- minor_ticks = np .arange (mi - 5 , ma + 5 + 5 , 1 )
398- ax .set_xticks (minor_ticks , minor = True )
399- ax .set_yticks (minor_ticks , minor = True )
400-
401- ax .grid (which = "both" )
412+ if "xlim" in kwargs :
413+ ax .set_xlim (kwargs ["xlim" ])
414+ if "ylim" in kwargs :
415+ ax .set_ylim (kwargs ["ylim" ])
402416
403417 return fig
404418
@@ -433,7 +447,7 @@ def plot1d(self, **kwargs):
433447 qty = pdata_names [0 ]
434448
435449 layout = patch .patch_datas [qty ].layout
436- nbrGhosts = layout . nbrGhostFor ( qty )
450+ nbrGhosts = patch . patch_datas [ qty ]. ghosts_nbr
437451 val = patch .patch_datas [qty ][patch .box ]
438452 x = patch .patch_datas [qty ].x [nbrGhosts [0 ] : - nbrGhosts [0 ]]
439453 label = "L{level}P{patch}" .format (level = lvl_nbr , patch = ip )
@@ -544,9 +558,10 @@ def plot2d(self, **kwargs):
544558 if "ylim" in kwargs :
545559 ax .set_ylim (kwargs ["ylim" ])
546560
547- divider = make_axes_locatable (ax )
548- cax = divider .append_axes ("right" , size = "5%" , pad = 0.08 )
549- plt .colorbar (im , ax = ax , cax = cax )
561+ if kwargs .get ("cbar" , True ):
562+ divider = make_axes_locatable (ax )
563+ cax = divider .append_axes ("right" , size = "5%" , pad = 0.08 )
564+ fig .colorbar (im , ax = ax , cax = cax )
550565
551566 if kwargs .get ("legend" , None ) is not None :
552567 ax .legend ()
0 commit comments