File tree Expand file tree Collapse file tree 13 files changed +24
-1
lines changed Expand file tree Collapse file tree 13 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 1+ --- 
2+ ' @e2b/data-extractor ' patch 
3+ --- 
4+ 
5+ Omit blank figures
Original file line number Diff line number Diff line change @@ -88,14 +88,22 @@ def get_chart_from_ax(
8888    return  chart 
8989
9090
91+ def  is_figure_blank (axes : List [Axes ]) ->  bool :
92+     """Check if a Matplotlib figure is blank (has no user-added artists).""" 
93+     for  ax  in  axes :
94+         if  ax .has_data ():
95+             return  False   # The figure contains user-added data 
96+     return  True   # No data found, figure is blank 
97+ 
98+ 
9199def  chart_figure_to_chart (figure : Figure ) ->  Optional [Chart ]:
92100    """ 
93101    This method is used to extract data from the figure object to a dictionary 
94102    """ 
95103    # Get all Axes objects from the Figure 
96104    axes  =  figure .get_axes ()
97105
98-     if  not  axes :
106+     if  not  axes   or   is_figure_blank ( axes ) :
99107        return 
100108    elif  len (axes ) >  1 :
101109        return  SuperChart (figure = figure )
File renamed without changes.
Original file line number Diff line number Diff line change 1+ import  matplotlib .pyplot  as  plt 
2+ 
3+ from  e2b_charts  import  chart_figure_to_chart 
4+ from  e2b_charts .charts  import  BarChart , ChartType 
5+ 
6+ 
7+ def  test_blank_chart ():
8+     figure , _  =  plt .subplots ()
9+     chart  =  chart_figure_to_chart (figure )
10+     assert  chart  is  None 
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments