@@ -358,6 +358,8 @@ def box_to_Rectangle(self, box):
358358 return Rectangle (box .lower , * box .shape )
359359
360360 def plot_2d_patches (self , ilvl , collections , ** kwargs ):
361+ from matplotlib .patches import Rectangle
362+
361363 if isinstance (collections , list ) and all (
362364 [isinstance (el , Box ) for el in collections ]
363365 ):
@@ -368,35 +370,47 @@ def plot_2d_patches(self, ilvl, collections, **kwargs):
368370 level_domain_box = self .level_domain_box (ilvl )
369371 mi , ma = level_domain_box .lower .min (), level_domain_box .upper .max ()
370372
371- fig , ax = kwargs .get ("subplot" , plt .subplots (figsize = (6 , 6 )))
373+ fig , ax = kwargs .get ("subplot" , plt .subplots (figsize = (16 , 16 )))
374+
375+ i0 , j0 = level_domain_box .lower
376+ i1 , j1 = level_domain_box .upper
377+ ij = np .zeros ((i1 - i0 + 1 , j1 - j0 + 1 )) + np .nan
378+ ix = np .arange (i0 , i1 + 1 )
379+ iy = np .arange (j0 , j1 + 1 )
372380
373381 for collection in collections :
374- facecolor = collection .get ("facecolor" , "none" )
375- edgecolor = collection .get ("edgecolor" , "purple" )
376- alpha = collection .get ("alpha" , 1 )
377- rects = [self .box_to_Rectangle (box ) for box in collection ["boxes" ]]
378-
379- ax .add_collection (
380- PatchCollection (
381- rects , facecolor = facecolor , alpha = alpha , edgecolor = edgecolor
382- )
383- )
382+ value = collection .get ("value" , np .nan )
383+ for box in collection ["boxes" ]:
384+ i0 , j0 = box .lower
385+ i1 , j1 = box .upper
386+ ij [i0 : i1 + 1 , j0 : j1 + 1 ] = value
387+ if "coords" in collection :
388+ for coords in collection ["coords" ]:
389+ ij [coords ] = collection ["value" ]
390+
391+ ax .pcolormesh (ix , iy , ij .T , edgecolors = "k" , cmap = "jet" )
392+ ax .set_xticks (ix )
393+ ax .set_yticks (iy )
394+
395+ for patch in self .level (ilvl ).patches :
396+ box = patch .box
397+ r = Rectangle (box .lower - 0.5 , * (box .upper + 0.5 ))
398+
399+ r .set_edgecolor ("r" )
400+ r .set_facecolor ("none" )
401+ r .set_linewidth (2 )
402+ ax .add_patch (r )
384403
385404 if "title" in kwargs :
386405 from textwrap import wrap
387406
388407 xfigsize = int (fig .get_size_inches ()[0 ] * 10 ) # 10 characters per inch
389408 ax .set_title ("\n " .join (wrap (kwargs ["title" ], xfigsize )))
390409
391- major_ticks = np .arange (mi - 5 , ma + 5 + 5 , 5 )
392- ax .set_xticks (major_ticks )
393- ax .set_yticks (major_ticks )
394-
395- minor_ticks = np .arange (mi - 5 , ma + 5 + 5 , 1 )
396- ax .set_xticks (minor_ticks , minor = True )
397- ax .set_yticks (minor_ticks , minor = True )
398-
399- ax .grid (which = "both" )
410+ if "xlim" in kwargs :
411+ ax .set_xlim (kwargs ["xlim" ])
412+ if "ylim" in kwargs :
413+ ax .set_ylim (kwargs ["ylim" ])
400414
401415 return fig
402416
@@ -431,7 +445,8 @@ def plot1d(self, **kwargs):
431445 qty = pdata_names [0 ]
432446
433447 layout = patch .patch_datas [qty ].layout
434- nbrGhosts = layout .nbrGhostFor (qty )
448+ # nbrGhosts = layout.nbrGhostFor(qty) # bad !!!
449+ nbrGhosts = patch .patch_datas [qty ].ghosts_nbr
435450 val = patch .patch_datas [qty ][patch .box ]
436451 x = patch .patch_datas [qty ].x [nbrGhosts [0 ] : - nbrGhosts [0 ]]
437452 label = "L{level}P{patch}" .format (level = lvl_nbr , patch = ip )
@@ -542,9 +557,10 @@ def plot2d(self, **kwargs):
542557 if "ylim" in kwargs :
543558 ax .set_ylim (kwargs ["ylim" ])
544559
545- divider = make_axes_locatable (ax )
546- cax = divider .append_axes ("right" , size = "5%" , pad = 0.08 )
547- plt .colorbar (im , ax = ax , cax = cax )
560+ if kwargs .get ("cbar" , True ):
561+ divider = make_axes_locatable (ax )
562+ cax = divider .append_axes ("right" , size = "5%" , pad = 0.08 )
563+ fig .colorbar (im , ax = ax , cax = cax )
548564
549565 if kwargs .get ("legend" , None ) is not None :
550566 ax .legend ()
0 commit comments