FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Optimize line drawing for 1M+ vertices · TinkerForFun/finplot@fe38188 · GitHub

Commit fe38188

Browse files
committed
Optimize line drawing for 1M+ vertices
Also added 1s resolution for the real-time complicated example.
1 parent dbf1cad commit fe38188

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

‎finplot/__init__.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,6 +1617,7 @@ def plot(x, y=None, color=None, width=1, ax=None, style=None, legend=None, zooms
16171617
if style is None or any(ch in style for ch in '-_.'):
16181618
connect_dots = 'finite' # same as matplotlib; use datasrc.standalone=True if you want to keep separate intervals on a plot
16191619
item = ax.plot(x, y, pen=_makepen(color=used_color, style=style, width=width), name=legend, connect=connect_dots)
1620+
item.setClipToView(True)
16201621
item.setDownsampling(auto=True, method='subsample')
16211622
item.setZValue(5)
16221623
else:

‎finplot/examples/complicated.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
99
This example includes dipping in to the internals of finplot and
1010
the underlying lib pyqtgraph, which is not part of the API per se,
11-
and may thus change in the future. If so happens, this example
12-
will be updated to reflect such changes.
11+
and may thus change in the. If so happens, this example will be
12+
updated to reflect such changes.
1313
1414
Included is also some third-party libraries to make the example
1515
more realistic.
@@ -29,9 +29,9 @@
2929
import websocket
3030

3131

32-
class BinanceFutureWebsocket:
32+
class BinanceWebsocket:
3333
def __init__(self):
34-
self.url = 'wss://fstream.binance.com/stream'
34+
self.url = 'wss://stream.binance.com/stream'
3535
self.symbol = None
3636
self.interval = None
3737
self.ws = None
@@ -113,8 +113,8 @@ def on_error(self, error, *args, **kwargs):
113113

114114

115115
def do_load_price_history(symbol, interval):
116-
url = 'https://www.binance.com/fapi/v1/klines?symbol=%s&interval=%s&limit=%s' % (symbol, interval, 1000)
117-
print('loading binance future %s %s' % (symbol, interval))
116+
url = 'https://www.binance.com/api/v1/klines?symbol=%s&interval=%s&limit=%s' % (symbol, interval, 1000)
117+
print('loading binance %s %s' % (symbol, interval))
118118
d = requests.get(url).json()
119119
df = pd.DataFrame(d, columns='Time Open High Low Close Volume a b c d e f'.split())
120120
df = df.astype({'Time':'datetime64[ms]', 'Open':float, 'High':float, 'Low':float, 'Close':float, 'Volume':float})
@@ -390,7 +390,7 @@ def create_ctrl_panel(win):
390390
layout.setColumnMinimumWidth(1, 30)
391391

392392
panel.interval = QComboBox(panel)
393-
[panel.interval.addItem(i) for i in '1d 4h 1h 30m 15m 5m 1m'.split()]
393+
[panel.interval.addItem(i) for i in '1d 4h 1h 30m 15m 5m 1m 1s'.split()]
394394
panel.interval.setCurrentIndex(6)
395395
layout.addWidget(panel.interval, 0, 2)
396396
panel.interval.currentTextChanged.connect(change_asset)
@@ -418,11 +418,11 @@ def create_ctrl_panel(win):
418418
fplt.y_pad = 0.07 # pad some extra (for control panel)
419419
fplt.max_zoom_points = 7
420420
fplt.autoviewrestore()
421-
ax,ax_rsi = fplt.create_plot('Complicated Binance Futures Example', rows=2, init_zoom_periods=300)
421+
ax,ax_rsi = fplt.create_plot('Complicated Binance Example', rows=2, init_zoom_periods=300)
422422
axo = ax.overlay()
423423

424424
# use websocket for real-time
425-
ws = BinanceFutureWebsocket()
425+
ws = BinanceWebsocket()
426426

427427
# hide rsi chart to begin with; show x-axis of top plot
428428
ax_rsi.hide()
@@ -432,5 +432,5 @@ def create_ctrl_panel(win):
432432
ctrl_panel = create_ctrl_panel(ax.vb.win)
433433
dark_mode_toggle(True)
434434
change_asset()
435-
fplt.timer_callback(realtime_update_plot, 1) # update every second
435+
fplt.timer_callback(realtime_update_plot, 0.5) # update twice every second
436436
fplt.show()

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL