Comments (6)
I'm happy you like it!
I wanted to suggest similar solution as you already did. I will add this feature in future release of pglive, so it's available for other users as well.
Feel free to suggest any other features you would like to have or if you have any suggestions.
Good luck with your project.
from pglive.
Thanks for trying out pglive!
Since you are not providing any additional info to your question, I will just response to my best understanding.
The easiest way to preload plot with some data is to use callbacks of DataConnector
. It provides callback to apeend one data point: cb_append_data_point
or set of data cb_set_data
.
In your case you want to use cb_set_data
first, before adding another data points.
Here is updated candlestick example:
import signal
from threading import Thread
import pglive.examples_pyqt5 as examples
from pglive.sources.data_connector import DataConnector
from pglive.sources.live_candleStickPlot import LiveCandleStickPlot
from pglive.sources.live_plot_widget import LivePlotWidget
"""
In this example Scatter plot is displayed.
"""
win = LivePlotWidget(title="Candlestick Plot @ 10Hz")
plot = LiveCandleStickPlot()
win.addItem(plot)
data_connector = DataConnector(plot, max_points=50, update_rate=10)
win.show()
x_data = [-140, -130, -120, -110, -100, -90, -80, -70, -60, -50, -40, -30, -20, -10]
y_data = [[0.0249974, 0.01999867, -0.15300133, 0.1699974],
[0.27154694, 0.21822962, -0.30077038, 0.41154694],
[0.501213, 0.40776045, -0.50923955, 0.533213],
[0.69971608, 0.58103516, -0.28296484, 1.19471608],
[0.85471419, 0.73114583, 0.31014583, 1.34571419],
[0.95657032, 0.85210802, 0.51010802, 1.25857032],
[0.99895153, 0.93909936, 0.86309936, 1.55695153],
[0.98398595, 0.98544973, 0.65098595, 1.46244973],
[0.90929743, 0.9995736, 0.67529743, 1.6775736],
[0.7780732, 0.97384763, 0.0710732, 1.13184763],
[0.59847214, 0.90929743, -0.04452786, 0.99729743],
[0.38166099, 0.8084964, -0.09333901, 0.8374964],
[0.14112001, 0.67546318, 0.11212001, 0.74546318],
[-0.57156132, 0.14112001, -0.87856132, 0.46312001]]
data_connector.cb_set_data(y=y_data, x=x_data)
Thread(target=examples.candle_generator, args=(data_connector,)).start()
signal.signal(signal.SIGINT, lambda sig, frame: examples.stop())
examples.app.exec()
examples.stop()
If you need something else, please let me know.
from pglive.
it is working for me, thank so you so much. this is my show case with my tiny project.
and one more question, please.
how can i real-time update data for only the last candlestick.
from pglive.
I made this function
def cb_update_last_data_point(self, y: Union[int, float, List], x: Union[int, float] = None, **kwargs) -> None:
"""Append new data point"""
if self._skip_update():
return
with self.data_lock:
if x == self.x[-1]:
self.y.pop()
self.y.append(y)
else:
self.x.append(x)
self.y.append(y)
if self.tick_position_indexes is not None:
if len(self.tick_position_indexes) == 0:
self.tick_position_indexes.append(0.0)
elif len(self.tick_position_indexes) == self.tick_position_indexes.maxlen:
self.tick_position_indexes.rotate(-1)
else:
self.tick_position_indexes.append(self.tick_position_indexes[-1] + 1.0)
self.last_update = time.perf_counter()
if not self._skip_plot():
self._update_data(**kwargs)
self.sig_data_roll_tick.emit(self, self.rolling_index)
self.rolling_index += 1
and put it on DataConnector class. and update date last candlestick work correctly. Thank you again for pglive. it is really good
from pglive.
I am using pglive for my project, so i think i will be have more problem, can I ask you for support?
and one more tiny thing i change to make leading_line work correctly with candlestick data format [[open, close, min, max]
def update_leading_line(self) -> None:
"""Leading line will display all four fields"""
last_x_point = self.x_data[-1]
last_y_point = self.y_data[-1][1] # 1 is index of close price in the list data format like [[open, close, min, max], ...]
if self._vl_kwargs is not None:
self._vl_kwargs["line"].setPos(last_x_point)
if self._hl_kwargs is not None:
self._hl_kwargs["line"].setPos(last_y_point)
y_text = str([round(x, 4) for x in self.y_data[-1]])
self.update_leading_text(last_x_point, last_y_point, y_text=y_text)
from pglive.
Sure, when you have any problem / question, please open new issue for each problem, so it's also easier for others to follow as well.
As for the leading line for candlestick.
You probably want to modify it for your specific needs (as you already did). I mostly did it in general way for everyone.
last_x_point
and last_y_point
is just used to place line at certain position on the axis. So when you use horizontal leading line last_y_point
is used, and last_x_point
for vertical leading line. I designed it for vertical leading line, so timestamp is usually used as last_x_point
and last_y_point
is ignored unless horizontal_leading_line is used.
from pglive.
Related Issues (20)
- LiveAxisRange Multiple Plots Auto range if plot turned off. HOT 4
- Question: If using "Promoted Widget", How to add LivePlotWidget(title=...., axisItems=......, **kwargs) HOT 2
- "cb_append_data_point" leads to runtime error if no existing points are present HOT 7
- Support for "connect" attribute of pyqtgraph PlotDataItem/PlotCurveItem? HOT 2
- .removeItem() interferes with auto-range HOT 2
- Custom ViewBox HOT 4
- Question, possible issue HOT 8
- Feature request (continuation on the previous issue) HOT 6
- How to append data from list or array HOT 5
- Poetry Update HOT 4
- How to clear data from DataConnector? HOT 3
- Feature request: Add crosshair after LivePlotWidget constructor called HOT 2
- Understanding DataConnector update_rate and data append time HOT 9
- Tick strings on the bottom axis overlaps with its label HOT 3
- Roll on tick HOT 4
- ValueError: operands could not be broadcast together with shapes (2,) (0,) HOT 14
- Formatting x axis timestamp for Axis.TIME HOT 4
- TypeError: ufunc 'isfinite' not supported for the input types HOT 2
- Bug or Feature? LivePlotWidget "bottom" axis ticks labels disappear if string is more than simple one liner
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pglive.