55from plotly .subplots import make_subplots
66
77import maxplotlib .backends .matplotlib .utils as plt_utils
8- import maxplotlib .subfigure .line_plot as lp
9- import maxplotlib .subfigure .tikz_figure as tf
8+ from maxplotlib .subfigure .line_plot import LinePlot
9+ from maxplotlib .subfigure .tikz_figure import TikzFigure
1010
1111
1212class Canvas :
@@ -70,6 +70,38 @@ def generate_new_rowcol(self, row, col):
7070 assert col is not None , "Not enough columns!"
7171 return row , col
7272
73+ def add_line (
74+ self ,
75+ x_data ,
76+ y_data ,
77+ layer = 0 ,
78+ subplot : LinePlot | None = None ,
79+ row : int | None = None ,
80+ col : int | None = None ,
81+ plot_type = "plot" ,
82+ ** kwargs ,
83+ ):
84+ if row is not None and col is not None :
85+ try :
86+ subplot = self ._subplot_matrix [row ][col ]
87+ except KeyError :
88+ raise ValueError ("Invalid subplot position." )
89+ else :
90+ row , col = 0 , 0
91+ subplot = self ._subplot_matrix [row ][col ]
92+
93+ if subplot is None :
94+ row , col = self .generate_new_rowcol (row , col )
95+ subplot = self .add_subplot (col = col , row = row )
96+
97+ subplot .add_line (
98+ x_data = x_data ,
99+ y_data = y_data ,
100+ layer = layer ,
101+ plot_type = plot_type ,
102+ ** kwargs ,
103+ )
104+
73105 def add_tikzfigure (self , ** kwargs ):
74106 """
75107 Adds a subplot to the figure.
@@ -87,7 +119,7 @@ def add_tikzfigure(self, **kwargs):
87119 row , col = self .generate_new_rowcol (row , col )
88120
89121 # Initialize the LinePlot for the given subplot position
90- tikz_figure = tf . TikzFigure (** kwargs )
122+ tikz_figure = TikzFigure (** kwargs )
91123 self ._subplot_matrix [row ][col ] = tikz_figure
92124
93125 # Store the LinePlot instance by its position for easy access
@@ -97,7 +129,13 @@ def add_tikzfigure(self, **kwargs):
97129 self ._subplots [label ] = tikz_figure
98130 return tikz_figure
99131
100- def add_subplot (self , col : int | None = None , row : int | None = None , label : str | None = None , ** kwargs ):
132+ def add_subplot (
133+ self ,
134+ col : int | None = None ,
135+ row : int | None = None ,
136+ label : str | None = None ,
137+ ** kwargs ,
138+ ):
101139 """
102140 Adds a subplot to the figure.
103141
@@ -108,11 +146,10 @@ def add_subplot(self, col: int | None = None, row: int | None = None, label: str
108146 - label (str): Label to identify the subplot.
109147 """
110148
111-
112149 row , col = self .generate_new_rowcol (row , col )
113150
114151 # Initialize the LinePlot for the given subplot position
115- line_plot = lp . LinePlot (col = col , row = row , label = label , ** kwargs )
152+ line_plot = LinePlot (col = col , row = row , label = label , ** kwargs )
116153 self ._subplot_matrix [row ][col ] = line_plot
117154
118155 # Store the LinePlot instance by its position for easy access
@@ -171,10 +208,8 @@ def plot(self, backend="matplotlib", savefig=False, layers=None):
171208
172209 def show (self , backend = "matplotlib" ):
173210 if backend == "matplotlib" :
174- fig , axs = self .plot (backend = "matplotlib" , savefig = False , layers = None )
175- print ('hmm' )
211+ self .plot (backend = "matplotlib" , savefig = False , layers = None )
176212 self ._matplotlib_fig .show ()
177- plt .show ()
178213 elif backend == "plotly" :
179214 plot = self .plot_plotly (savefig = False )
180215 else :
0 commit comments