-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render lines on zoom #419
Comments
Yeah, I'm feeling it too during initial render/zoom sometimes. How many lines are we talking, and over how many data points (timestamps)? Do you only get lag during initial delay and when zooming, or also when moving the crosshair around? |
I have for example in my chart 3727 lines. Overall I have 8516 data points. It gets laggy when zooming and also when I move it left or right. The crosshair is not being affected by this. |
May I ask what kind of lines? Could you make a tiny example to clarify? |
Yeah for example I am coloring the tails of the candles based on the trend, if the trend is up the candle tails will be green and if the trend is down the candle tails will be red.
By the way I don't know if there is a better way of doing this without adding lines so this is what I came up with. |
Yeah, that's going to be expensive. Hm. Best is to extend the class This is a feature that could be made more accessible for each data point. I think many people have similar problems, so I'll try to see if I can figure something out that can be used for a per-point basis coloring. It's going to take some time to figure out though, so in the mean while the above recommendation is the best I can do. GL! |
I tried to so something like this: Extend the CandlestickItem class: class CandlestickItemExtend(fplt.CandlestickItem):
def __init__(self, ax, datasrc, draw_body, draw_shadow, candle_width, colorfunc, resamp=None):
super().__init__(ax, datasrc, draw_body, draw_shadow, candle_width, colorfunc, resamp=None)
def generate_picture(self, boundingRect, up_trend_data=None, dn_trend_data=None):
super().generate_picture(boundingRect)
p = self.painter
if up_trend_data is not None:
p.setPen(pg.mkPen('#00FF00', width=3))
for _, row in up_trend_data.iterrows():
x = row['date']
low, high = row['low'], row['high']
p.drawLine(QtCore.QPointF(x, low), QtCore.QPointF(x, high))
if dn_trend_data is not None:
p.setPen(pg.mkPen('#FF0000', width=3))
for _, row in dn_trend_data.iterrows():
x = row['date']
low, high = row['low'], row['high']
p.drawLine(QtCore.QPointF(x, low), QtCore.QPointF(x, high)) Extend candlestick_ochl def my_candlestick_ochl(self, datasrc, draw_body=True, draw_shadow=True, candle_width=0.6, ax=None, colorfunc=fplt.price_colorfilter, **kwargs):
up_trend_df = self.df.loc[self.df['trend'] == 'up', ['date', 'high', 'low']]
dn_trend_df = self.df.loc[self.df['trend'] == 'down', ['date', 'high', 'low']]
view_bounds = self.ax.vb.viewRect()
bounding_rect = QtCore.QRectF(view_bounds.x(), view_bounds.y(), view_bounds.width(), view_bounds.height())
item = fplt.candlestick_ochl(datasrc, draw_body=draw_body, draw_shadow=draw_shadow, candle_width=candle_width, ax=ax, colorfunc=colorfunc)
data = CandlestickItemExtend(self.ax, datasrc, draw_body=draw_body, draw_shadow=draw_shadow, candle_width=candle_width, colorfunc=colorfunc)
data.generate_picture(bounding_rect, up_trend_df, dn_trend_df) this is how I call the function:
For some reason this does not work I get an error:
Am I any close? Edit: I was able to overcome this by creating datasrc like so: data = fplt._create_datasrc(self.ax, datasrc, ncols=5)
item = fplt.candlestick_ochl(datasrc, draw_body=draw_body, draw_shadow=draw_shadow, candle_width=candle_width, ax=ax, colorfunc=colorfunc)
candle = CandlestickItemExtend(self.ax, data, draw_body=draw_body, draw_shadow=draw_shadow, candle_width=candle_width, colorfunc=colorfunc)
candle.generate_picture(bounding_rect, up_trend_df, dn_trend_df) Now i get :
The chart opens but I don't see the colors |
You see, you need to override the class just like you did, and then use it within the finplot library. Something like this:
I was wrong, don't think you need to override |
Haha, glad to hear it! Sorry, no I have no idea where the big fat red line is coming from. I suspect that you're rendering other stuff than just the candlesticks in your chart? |
I wish this was the case but if I am not extending the CandlestickItem then it won't show me those candles. I am using the same df for both cases. |
Hi again, sorry for the delay! Is this still a problem? If so: could you post some minimal code that I can use to reproduce the issue? |
Hi, I solved adding an "epsilon"
|
@IlanKalendarov Is this still a problem, or did you solve it? |
Hey, Is there a way to render lines on zoom?
For example you have
lod_candles
lod_labels
It would be great if you would have the same functionality for lines, as I have lots of them and the chart is being kind of laggy.
Thanks!
The text was updated successfully, but these errors were encountered: