1212 setup_plotstyle ,
1313 setup_tex_fonts ,
1414)
15+ from maxplotlib .backends .plotext import PlotextFigure , create_plotext_figure
1516from maxplotlib .colors .colors import Color
1617from maxplotlib .linestyle .linestyle import Linestyle
1718from maxplotlib .subfigure .line_plot import LinePlot
@@ -199,6 +200,7 @@ def __init__(
199200 self ._plotted = False
200201 self ._matplotlib_fig = None
201202 self ._matplotlib_axes = None
203+ self ._plotext_figure = None
202204 self ._suptitle : str | None = None
203205 self ._suptitle_kwargs : dict = {}
204206
@@ -690,6 +692,33 @@ def savefig(
690692 fig .savefig (full_filepath )
691693 if verbose :
692694 print (f"Saved { full_filepath } " )
695+ elif backend == "plotext" :
696+ if layer_by_layer :
697+ layers = []
698+ for layer in self .layers :
699+ layers .append (layer )
700+ figure = self .plot (
701+ backend = "plotext" ,
702+ savefig = False ,
703+ layers = layers ,
704+ )
705+ _fn = f"{ filename_no_extension } _{ layers } .{ extension } "
706+ figure .savefig (_fn )
707+ print (f"Saved { _fn } " )
708+ else :
709+ if layers is None :
710+ layers = self .layers
711+ full_filepath = filename
712+ else :
713+ full_filepath = f"{ filename_no_extension } _{ layers } .{ extension } "
714+ figure = self .plot (
715+ backend = "plotext" ,
716+ savefig = False ,
717+ layers = layers ,
718+ )
719+ figure .savefig (full_filepath )
720+ if verbose :
721+ print (f"Saved { full_filepath } " )
693722
694723 def plot (
695724 self ,
@@ -709,6 +738,12 @@ def plot(
709738 )
710739 elif backend == "plotly" :
711740 return self .plot_plotly (savefig = savefig )
741+ elif backend == "plotext" :
742+ return self .plot_plotext (
743+ savefig = savefig ,
744+ layers = layers ,
745+ verbose = verbose ,
746+ )
712747 elif backend == "tikzfigure" :
713748 return self .plot_tikzfigure (savefig = savefig )
714749 else :
@@ -733,6 +768,14 @@ def show(
733768 # self._matplotlib_fig.show()
734769 elif backend == "plotly" :
735770 self .plot_plotly (savefig = False )
771+ elif backend == "plotext" :
772+ figure = self .plot_plotext (
773+ savefig = False ,
774+ layers = layers ,
775+ verbose = verbose ,
776+ )
777+ figure .show ()
778+ return figure
736779 elif backend == "tikzfigure" :
737780 fig = self .plot_tikzfigure (savefig = False , verbose = verbose )
738781 # TikzFigure handles all rendering (single or multi-subplot)
@@ -890,6 +933,32 @@ def plot_tikzfigure(
890933
891934 return fig
892935
936+ def plot_plotext (
937+ self ,
938+ savefig : bool = False ,
939+ layers : list | None = None ,
940+ verbose : bool = False ,
941+ ) -> PlotextFigure :
942+ if verbose :
943+ print ("Generating plotext figure..." )
944+
945+ figure = create_plotext_figure (self .nrows , self .ncols )
946+
947+ for row , col , subplot in self .iter_subplots ():
948+ ax = figure if (self .nrows , self .ncols ) == (1 , 1 ) else figure .subplot (row + 1 , col + 1 )
949+ if isinstance (subplot , TikzFigure ):
950+ raise NotImplementedError (
951+ "tikzfigure subplots cannot be rendered with the plotext backend."
952+ )
953+ subplot .plot_plotext (ax , layers = layers )
954+
955+ wrapped = PlotextFigure (figure = figure , suptitle = self ._suptitle )
956+ if savefig and isinstance (savefig , str ):
957+ wrapped .savefig (savefig )
958+
959+ self ._plotext_figure = wrapped
960+ return wrapped
961+
893962 def plot_plotly (self , show = True , savefig = None , usetex = False ):
894963 """
895964 Generate and optionally display the subplots using Plotly.
0 commit comments