Skip to content
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

Two axes with different intervals #519

Open
StephanHQ opened this issue May 7, 2024 · 7 comments
Open

Two axes with different intervals #519

StephanHQ opened this issue May 7, 2024 · 7 comments

Comments

@StephanHQ
Copy link

Hello,

my question is, how can finplot plot two different df which both have different intervals. Also the second df has no real interval, but sporadic values. I managed to plot both, but both ax do not align. The second df is currently being plotted with equal x spacing between rows, although the timestamp significantly varies between each one.
Bildschirmfoto 2024-05-07 um 15 36 24

@highfestiva
Copy link
Owner

You can fill in null data in the missing time intervals on the second dataframe, then you should be able to display them in the same axis.

@StephanHQ
Copy link
Author

Thank your for your lightning speed reply. I tried that before and i receive "Segmentation fault: 11". I uploaded the used df just in case. this function is used when the errors occurs: fplt.plot(df['pivot_point'], ax=ax, style='o-', color='#ff00ff')
ofc using this function fplt.plot(df['pivot_point'].dropna(), ax=ax, style='o-', color='#ff00ff') doesnt lead to an error.

df.csv

@highfestiva
Copy link
Owner

There is no timestamp on your data. Is this intended? The pivot_point is all null, so .dropna() is going to lead to an empty sequence.

@StephanHQ
Copy link
Author

my bad. the df has been indexed after timestamp. df.to_csv doesnt inherit timestamp indexing. I adjusted to normal indexing and inserted timestamp as a column (see dv.csv).
dv.csv
Im using this plot function now: fplt.plot(df['timestamp'],df['pivot_point'], ax=ax, style='o-', color='#ff00ff')
However, it still leads to the error: "Segmentation fault: 11".

@highfestiva
Copy link
Owner

That sounds like I'm supplying Qt with some bad data, or possibly a bug in Qt. Any chance you could create a minimal example with only the plot call and only the data causing the error?

@StephanHQ
Copy link
Author

StephanHQ commented May 16, 2024

I can not currently recreate the error in a single file. I will take some more time to do that. However, going to my main question, how can we align both plots on timestamp x? I provided the csv and the py to show you.

data.csv

Code start

import finplot as fplt
import pandas as pd

data = pd.read_csv('data.csv', parse_dates=['timestamp'])
data.set_index('timestamp', inplace=True)
ax, ax2 = fplt.create_plot('Stock Price with Zigzag Indicator', rows=2)

fplt.candlestick_ochl(data[['open', 'close', 'high', 'low']], ax=ax)
zigzag_points = data['pivot_point'].dropna()
fplt.plot(zigzag_points.index, zigzag_points.values, ax=ax2, color='#0000ff', width=1.5)

fplt.show()

@highfestiva
Copy link
Owner

Replace .dropna() with .interpolate()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants