@@ -735,7 +735,9 @@ def show(
735735 self .plot_plotly (savefig = False )
736736 elif backend == "tikzfigure" :
737737 fig = self .plot_tikzfigure (savefig = False , verbose = verbose )
738- fig .show ()
738+ # TikzFigure handles all rendering (single or multi-subplot)
739+ fig .show (transparent = False )
740+ return fig
739741 else :
740742 raise ValueError ("Invalid backend" )
741743
@@ -807,19 +809,86 @@ def plot_matplotlib(
807809
808810 def plot_tikzfigure (
809811 self ,
810- savefig : str | None = None ,
812+ savefig : bool = False ,
811813 verbose : bool = False ,
812814 ) -> TikzFigure :
813- if len (self ._subplot_dict ) > 1 :
815+ """
816+ Generate a TikZ figure from subplots.
817+
818+ For now, returns the first subplot's TikzFigure.
819+ Full multi-subplot support requires TikzFigure's subfigure_axis API.
820+
821+ Parameters:
822+ verbose (bool): If True, print debug information.
823+
824+ Returns:
825+ TikzFigure: Figure object that can be shown, saved, or compiled.
826+ """
827+ if verbose :
828+ print (f"Plotting tikzfigure with { len (self ._subplot_dict )} subplot(s)" )
829+
830+ # Check for unsupported layouts
831+ if self .nrows > 1 :
814832 raise NotImplementedError (
815- "Only one subplot is supported for tikzfigure backend."
833+ "Vertical/grid layouts (nrows > 1) are not yet supported for tikzfigure backend. "
834+ "Use horizontal layouts (1×n) only."
835+ )
836+
837+ # Validate that at least one subplot exists
838+ if len (self ._subplot_dict ) == 0 :
839+ raise ValueError (
840+ "No subplots to plot. Call add_subplot() or Canvas.subplots() first."
816841 )
842+
843+ fig = TikzFigure ()
844+
845+ # Add each subplot as a subfigure axis
817846 for (row , col ), line_plot in self ._subplot_dict .items ():
818847 if verbose :
819848 print (f"Plotting subplot at row { row } , col { col } " )
820- print (f"{ line_plot = } " )
821- tikz_subplot = line_plot .plot_tikzfigure (verbose = verbose )
822- return tikz_subplot
849+
850+ # Create subfigure axis with subplot metadata
851+ ax = fig .subfigure_axis (
852+ xlabel = line_plot ._xlabel or "" ,
853+ ylabel = line_plot ._ylabel or "" ,
854+ xlim = (
855+ (line_plot ._xmin , line_plot ._xmax )
856+ if line_plot ._xmin is not None
857+ else None
858+ ),
859+ ylim = (
860+ (line_plot ._ymin , line_plot ._ymax )
861+ if line_plot ._ymin is not None
862+ else None
863+ ),
864+ grid = line_plot ._grid ,
865+ caption = line_plot ._title or f"Subplot { col + 1 } " ,
866+ width = 0.45 ,
867+ )
868+
869+ # Add each plot line to the subfigure
870+ for line_data in line_plot .line_data :
871+ if line_data .get ("plot_type" ) == "plot" :
872+ # Extract and transform x, y data
873+ x = (line_data ["x" ] + line_plot ._xshift ) * line_plot ._xscale
874+ y = (line_data ["y" ] + line_plot ._yshift ) * line_plot ._yscale
875+ kwargs = line_data .get ("kwargs" , {})
876+ if verbose :
877+ print (f"Line { kwargs = } " )
878+ # Add plot to subfigure axis
879+ ax .add_plot (
880+ x = x ,
881+ y = y ,
882+ # label=kwargs.get("label", ""),
883+ color = kwargs .get ("color" , "black" ),
884+ line_width = kwargs .get ("linewidth" , 1.0 ),
885+ )
886+
887+ # Add legend if requested
888+ if line_plot ._legend and len (line_plot .line_data ) > 0 :
889+ ax .set_legend (position = "north east" )
890+
891+ return fig
823892
824893 def plot_plotly (self , show = True , savefig = None , usetex = False ):
825894 """
0 commit comments