Allows for plotting contents of the table visually in e.g. jupyter. If the table depends only on the bounded data sources, the plot will be generated right away. Otherwise (in streaming scenario), the plot will be auto-updating after running pw.run() Args: self (pw.Table):
(
self: pw.Table,
plotting_function,
sorting_col=None,
)
| 32 | @check_arg_types |
| 33 | @trace_user_frame |
| 34 | def plot( |
| 35 | self: pw.Table, |
| 36 | plotting_function, |
| 37 | sorting_col=None, |
| 38 | ): |
| 39 | """ |
| 40 | Allows for plotting contents of the table visually in e.g. jupyter. If the table |
| 41 | depends only on the bounded data sources, the plot will be generated right away. |
| 42 | Otherwise (in streaming scenario), the plot will be auto-updating after running pw.run() |
| 43 | |
| 44 | Args: |
| 45 | self (pw.Table): a table serving as a source of data |
| 46 | plotting_function (Callable[[ColumnDataSource], Plot]): function for creating plot |
| 47 | from ColumnDataSource |
| 48 | |
| 49 | Returns: |
| 50 | pn.Column: visualization which can be displayed immediately or passed as a dashboard widget |
| 51 | |
| 52 | Example: |
| 53 | |
| 54 | >>> import pathway as pw |
| 55 | >>> from bokeh.plotting import figure |
| 56 | >>> def func(source): |
| 57 | ... plot = figure(height=400, width=400, title="CPU usage over time") |
| 58 | ... plot.scatter('a', 'b', source=source, line_width=3, line_alpha=0.6) |
| 59 | ... return plot |
| 60 | >>> viz = pw.debug.table_from_pandas(pd.DataFrame({"a":[1,2,3],"b":[3,1,2]})).plot(func) # doctest: +SKIP |
| 61 | >>> type(viz) # doctest: +SKIP |
| 62 | <class 'panel.layout.base.Column'> |
| 63 | """ |
| 64 | import panel as pn |
| 65 | from bokeh.models import ColumnDataSource |
| 66 | |
| 67 | col_names = self.schema.column_names() |
| 68 | |
| 69 | gr = GraphRunner(parse_graph.G, debug=False, monitoring_level=MonitoringLevel.NONE) |
| 70 | bounded = gr.has_bounded_input(self) |
| 71 | |
| 72 | source = ColumnDataSource(data={colname: [] for colname in col_names}) |
| 73 | |
| 74 | plot = plotting_function(source) |
| 75 | viz = pn.Column( |
| 76 | pn.Row( |
| 77 | "Static preview" if bounded else "Streaming mode", |
| 78 | pn.widgets.TooltipIcon( |
| 79 | value=( |
| 80 | "Immediate table preview is possible as the table depends only on static inputs" |
| 81 | if bounded |
| 82 | else "Table depends on streaming inputs. Please run pw.run()" |
| 83 | ) |
| 84 | ), |
| 85 | ), |
| 86 | plot, |
| 87 | ) |
| 88 | |
| 89 | if bounded: |
| 90 | [captured] = gr.run_tables(self) |
| 91 | output_data = api.squash_updates(captured) |
nothing calls this directly
no test coverage detected