1+ """Plotting functions usefull for visual debugging."""
2+
13from pdfminer .layout import LTTextLineVertical
24
35
1517
1618
1719def extend_axe_lim (ax , bbox , margin = 10 ):
18- """Ensure the ax limits include the input bbox"""
20+ """Ensure the ax limits include the input bbox. """
1921 x0 , x1 = ax .get_xlim ()
2022 y0 , y1 = ax .get_ylim ()
2123 ax .set_xlim (min (x0 , bbox [0 ] - margin ), max (x1 , bbox [2 ] + margin ))
@@ -32,7 +34,27 @@ def draw_labeled_bbox(
3234 label_pos = "top,left" ,
3335 fontsize = 12 ,
3436):
35- """Utility drawing function to draw a box with an associated text label"""
37+ """Utility drawing function to draw a box with an associated text label.
38+
39+ Parameters
40+ ----------
41+ ax : matplotlib.axes.Axes
42+ matplotlib.axes.Axes (optional)
43+ bbox : [type]
44+ boundingbox
45+ text : string
46+ The text to be placed inside the box.
47+ color : str, optional
48+ The color of the box, by default "black"
49+ linewidth : int, optional
50+ The linewidth of the box, by default 3
51+ linestyle : str, optional
52+ The matplotlib linestyle, by default "solid"
53+ label_pos : str, optional
54+ The label postiion, by default "top,left"
55+ fontsize : int, optional
56+ The fontsize of the text in the box, by default 12
57+ """
3658 ax .add_patch (
3759 patches .Rectangle (
3860 (bbox [0 ], bbox [1 ]),
@@ -75,7 +97,8 @@ def draw_labeled_bbox(
7597
7698
7799def draw_pdf (table , ax ):
78- """Draw the content of the table's source pdf into the passed subplot
100+ """Draw the content of the table's source pdf into the passed subplot.
101+
79102 Parameters
80103 ----------
81104 table : camelot.core.Table
@@ -86,7 +109,8 @@ def draw_pdf(table, ax):
86109
87110
88111def draw_parse_constraints (table , ax ):
89- """Draw any user provided constraints (area, region, columns, etc)
112+ """Draw any user provided constraints (area, region, columns, etc).
113+
90114 Parameters
91115 ----------
92116 table : camelot.core.Table
@@ -114,7 +138,8 @@ def draw_parse_constraints(table, ax):
114138
115139
116140def draw_text (table , ax ):
117- """Draw text, horizontal in blue, vertical in red
141+ """Draw text, horizontal in blue, vertical in red.
142+
118143 Parameters
119144 ----------
120145 table : camelot.core.Table
@@ -132,7 +157,8 @@ def draw_text(table, ax):
132157
133158
134159def prepare_plot (table , ax = None ):
135- """Initialize plot and draw common components
160+ """Initialize plot and draw common components.
161+
136162 Parameters
137163 ----------
138164 table : camelot.core.Table
@@ -151,9 +177,12 @@ def prepare_plot(table, ax=None):
151177
152178
153179class PlotMethods :
180+ """Classmethod for plotting methods."""
181+
154182 def __call__ (self , table , kind = "text" , filename = None , ax = None ):
155- """Plot elements found on PDF page based on kind
156- specified, useful for debugging and playing with different
183+ """Plot elements found on PDF page based on kind specified.
184+
185+ Useful for debugging and playing with different
157186 parameters to get the best output.
158187
159188 Parameters
@@ -164,8 +193,9 @@ def __call__(self, table, kind="text", filename=None, ax=None):
164193 {'text', 'grid', 'contour', 'joint', 'line',
165194 'network_table_search'}
166195 The element type for which a plot should be generated.
167- filepath : str, optional (default: None)
196+ filename : str, optional (default: None)
168197 Absolute path for saving the generated plot.
198+ ax : matplotlib.axes.Axes (optional)
169199
170200 Returns
171201 -------
@@ -191,8 +221,7 @@ def __call__(self, table, kind="text", filename=None, ax=None):
191221 return plot_method (table , ax )
192222
193223 def text (self , table , ax = None ):
194- """Generates a plot for all text elements present
195- on the PDF page.
224+ """Generate a plot for all text elements present on the PDF page.
196225
197226 Parameters
198227 ----------
@@ -210,8 +239,7 @@ def text(self, table, ax=None):
210239
211240 @staticmethod
212241 def grid (table , ax = None ):
213- """Generates a plot for the detected table grids
214- on the PDF page.
242+ """Generate a plot for the detected table grids on the PDF page.
215243
216244 Parameters
217245 ----------
@@ -238,8 +266,7 @@ def grid(table, ax=None):
238266
239267 @staticmethod
240268 def contour (table , ax = None ):
241- """Generates a plot for all table boundaries present
242- on the PDF page.
269+ """Generate a plot for all table boundaries present on the PDF page.
243270
244271 Parameters
245272 ----------
@@ -251,7 +278,6 @@ def contour(table, ax=None):
251278 fig : matplotlib.fig.Figure
252279
253280 """
254-
255281 _for_lattice = table .flavor == "lattice"
256282 ax = prepare_plot (table , ax )
257283
@@ -274,7 +300,7 @@ def contour(table, ax=None):
274300
275301 @staticmethod
276302 def textedge (table , ax = None ):
277- """Generates a plot for relevant textedges.
303+ """Generate a plot for relevant textedges.
278304
279305 Parameters
280306 ----------
@@ -364,8 +390,7 @@ def textedge(table, ax=None):
364390
365391 @staticmethod
366392 def joint (table , ax = None ):
367- """Generates a plot for all line intersections present
368- on the PDF page.
393+ """Generate a plot for all line intersections present on the PDF page.
369394
370395 Parameters
371396 ----------
@@ -388,8 +413,7 @@ def joint(table, ax=None):
388413
389414 @staticmethod
390415 def line (table , ax = None ):
391- """Generates a plot for all line segments present
392- on the PDF page.
416+ """Generate a plot for all line segments present on the PDF page.
393417
394418 Parameters
395419 ----------
@@ -411,11 +435,13 @@ def line(table, ax=None):
411435
412436 @staticmethod
413437 def network_table_search (table , ax = None ):
414- """Generates a plot illustrating the steps of the network table search.
438+ """Generate a plot illustrating the steps of the network table search.
439+
415440 Parameters
416441 ----------
417442 table : camelot.core.Table
418443 ax : matplotlib.axes.Axes (optional)
444+
419445 Returns
420446 -------
421447 fig : matplotlib.fig.Figure
0 commit comments