Skip to content

Commit b4a8adc

Browse files
change to return holoviews figure when raw_figure=True
1 parent 7890f41 commit b4a8adc

9 files changed

Lines changed: 3202 additions & 83 deletions

File tree

docs/customization.ipynb

Lines changed: 3181 additions & 58 deletions
Large diffs are not rendered by default.

pfund_plot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
candlestick_plot as ohlc,
1414
candlestick_plot as kline,
1515
)
16+
from pfund_plot.layout import layout_plot as layout
1617

1718

1819
hvplot.extension('bokeh', 'plotly')

pfund_plot/layout.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
4+
def layout_plot():
5+
pass

pfund_plot/mosaic.py

Whitespace-only changes.

pfund_plot/plots/candlestick.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import narwhals as nw
1414
from bokeh.models import HoverTool, CrosshairTool
1515

16-
from pfund_plot.const.enums import DisplayMode, PlottingBackend, DataType
16+
from pfund_plot.const.enums import DisplayMode, DataType
1717
from pfund_plot.utils.validate import validate_data_type
1818
from pfund_plot.renderer import render
1919

@@ -129,7 +129,7 @@ def candlestick_plot(
129129
# TODO: using tick data to update the current candlestick
130130

131131

132-
display_mode, plotting_backend = DisplayMode[display_mode.lower()], PlottingBackend.bokeh
132+
display_mode = DisplayMode[display_mode.lower()]
133133
data_type: DataType = validate_data_type(data, streaming, import_hvplot=True)
134134
if data_type == DataType.datafeed:
135135
# TODO: get streaming data in the format of dataframe, and then call _validate_df
@@ -231,4 +231,4 @@ def _update_plot():
231231
sizing_mode='stretch_both',
232232
name=DEFAULT_STYLE['title'],
233233
)
234-
return render(fig, display_mode, raw_figure=raw_figure, plotting_backend=plotting_backend, periodic_callback=periodic_callback)
234+
return render(fig, display_mode, raw_figure=raw_figure, periodic_callback=periodic_callback)

pfund_plot/plots/dataframe.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
def dataframe_plot(
3535
data: tDataFrame | BaseFeed,
3636
display_mode: tDISPLAY_MODE = "notebook",
37-
dataframe_backend: tDATAFRAME_BACKEND = "tabulator",
37+
backend: tDATAFRAME_BACKEND = "tabulator",
3838
streaming: bool = False,
3939
streaming_freq: int = 1000, # in milliseconds
4040
max_streaming_data: int | None = None,
@@ -52,7 +52,7 @@ def dataframe_plot(
5252
streaming_freq: the update frequency of the streaming data in milliseconds
5353
max_streaming_data: maximum number of data points used when streaming.
5454
If None, data will continue to grow unbounded.
55-
dataframe_backend: backend to use for the dataframe plot.
55+
backend: backend to use for the dataframe plot.
5656
e.g. 'tabulator' or 'perspective'
5757
use Perspective if data size is large or more complicated data manipulation is needed.
5858
page_size: number of data points to display on each page when using Tabulator backend.
@@ -68,7 +68,7 @@ def dataframe_plot(
6868
and https://panel.holoviz.org/reference/panes/Perspective.html for Perspective backend.
6969
'''
7070

71-
display_mode, dataframe_backend = DisplayMode[display_mode.lower()], DataFrameBackend[dataframe_backend.lower()]
71+
display_mode, backend = DisplayMode[display_mode.lower()], DataFrameBackend[backend.lower()]
7272
data_type: DataType = validate_data_type(data, streaming, import_hvplot=False)
7373
if data_type == DataType.datafeed:
7474
# TODO: get streaming data in the format of dataframe, and then call _validate_df
@@ -77,10 +77,10 @@ def dataframe_plot(
7777
else:
7878
df = data
7979
df = convert_to_pandas_df(df)
80-
use_iframe_in_notebook = streaming or (dataframe_backend == DataFrameBackend.perspective)
80+
use_iframe_in_notebook = streaming or (backend == DataFrameBackend.perspective)
8181
iframe_style = None
8282

83-
if dataframe_backend == DataFrameBackend.tabulator:
83+
if backend == DataFrameBackend.tabulator:
8484
if max_streaming_data is not None and max_streaming_data < SUGGESTED_MIN_STREAMING_DATA_FOR_TABULATOR:
8585
# FIXME: this is a workaround for a bug in panel Tabulator, see if panel will fix it, or create a github issue
8686
print_warning(
@@ -109,7 +109,7 @@ def dataframe_plot(
109109
},
110110
**kwargs
111111
)
112-
elif dataframe_backend == DataFrameBackend.perspective:
112+
elif backend == DataFrameBackend.perspective:
113113
data_size = df.shape[0]
114114
if data_size > SUGGESTED_MAX_DATA_SIZE_FOR_PERSPECTIVE:
115115
print_warning(f"Data size is large (data_size={data_size}), consider using Tabulator backend, which supports for better performance.")
@@ -130,7 +130,7 @@ def dataframe_plot(
130130
**kwargs
131131
)
132132
else:
133-
raise ValueError(f"Unsupported dataframe backend: {dataframe_backend}")
133+
raise ValueError(f"Unsupported dataframe backend: {backend}")
134134

135135
if not streaming:
136136
periodic_callback = None
@@ -144,9 +144,9 @@ def _update_table():
144144
new_data['symbol'] = f'AAPL_{n}'
145145
n += 1
146146

147-
if dataframe_backend == DataFrameBackend.tabulator:
147+
if backend == DataFrameBackend.tabulator:
148148
table.stream(new_data, follow=watch, rollover=max_streaming_data)
149-
elif dataframe_backend == DataFrameBackend.perspective:
149+
elif backend == DataFrameBackend.perspective:
150150
table.stream(new_data, rollover=max_streaming_data)
151151
periodic_callback = pn.state.add_periodic_callback(_update_table, period=streaming_freq, start=False)
152152

pfund_plot/plots/orderbook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def orderbook_plot(
4040
display_mode=display_mode,
4141
streaming=streaming,
4242
streaming_freq=streaming_freq,
43-
dataframe_backend='perspective',
43+
backend='perspective',
4444
max_streaming_data=1,
4545
height=height,
4646
**kwargs

pfund_plot/renderer.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from __future__ import annotations
22
from typing import TYPE_CHECKING, Literal
33
if TYPE_CHECKING:
4-
from bokeh.plotting import figure
5-
from plotly.graph_objects import Figure
64
from panel.layout import Panel
75
from panel.widgets import Widget
86
from panel.pane import Pane
@@ -19,7 +17,7 @@
1917
import holoviews as hv
2018

2119
from pfund import print_warning
22-
from pfund_plot.const.enums import DisplayMode, PlottingBackend, NotebookType
20+
from pfund_plot.const.enums import DisplayMode, NotebookType
2321
from pfund_plot.utils.utils import get_notebook_type, get_free_port
2422

2523

@@ -61,7 +59,6 @@ def render(
6159
fig: Overlay | Panel | Pane | Widget,
6260
display_mode: Literal["notebook", "browser", "desktop"] | DisplayMode,
6361
raw_figure: bool = False,
64-
plotting_backend: Literal["bokeh", "plotly"] | PlottingBackend | None = None,
6562
periodic_callback: PeriodicCallback | None = None,
6663
use_iframe_in_notebook: bool = False,
6764
iframe_style: str | None = None,
@@ -84,13 +81,8 @@ def render(
8481
'''
8582
if isinstance(display_mode, str):
8683
display_mode = DisplayMode[display_mode.lower()]
87-
if isinstance(plotting_backend, str):
88-
plotting_backend = PlottingBackend[plotting_backend.lower()]
8984

9085
if raw_figure:
91-
assert plotting_backend is not None, "plotting_backend must be provided when raw_figure is True"
92-
# fig is of type "Overlay" -> convert to tFigure (bokeh figure or plotly figure)
93-
fig: figure | Figure = hv.render(fig, backend=plotting_backend.value)
9486
return fig
9587
else:
9688
if display_mode == DisplayMode.notebook:

pfund_plot/types/core.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from panel.widgets import Widget
44
from panel.pane import Pane
55
from holoviews.core.overlay import Overlay
6-
from bokeh.plotting import figure
7-
from plotly.graph_objects import Figure
86

97

10-
tFigure = figure | Figure | Overlay | Panel | Pane | Widget
8+
tFigure = Overlay | Panel | Pane | Widget
119
tOutput = tFigure | StoppableThread

0 commit comments

Comments
 (0)