-
Notifications
You must be signed in to change notification settings - Fork 658
make drawing trend lines simpler #42
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
Comments
You should be able to do this using the The tend line data will need to be in a list, or pandas series or dataframe, that has the same length and datetime index as your original OHLC data. If there are dates over which you do not want the lines to extend (as in the picture you have provided) you can simply use NaN values at the dates over which you do not want to see the trend lines. Let me know if that works for you. |
a couple of thoughts on this:
|
I did some experimenting with returning Figure and Axes. It didn't really work to allow me to add to the plot after calling Anyone who wants to should feel free to experiment with returning Figure and Axes and let me know if you can get it to work without fundamentally changing the design of Now, regarding trend lines, as I noted in a comment above, it is definitely possibly to plot them using the I am considering an implementing this as a kwarg to
|
Have you tried using It simply requires that you have a list (or a Series with a DatetimeIndex) that is the same length as the original dataframe. That list (or Series) should contain the values from your list of date,price tuples, each in their correct location within the list (or Series), and contain NaN at all other points. This is important, because the way that matplotlib handles not showing non-trading days is to use a range of integers for the x-axis (and then simply format them as dates). This is similar to This fact, the fact that internally the x-axis may be dates or may be integers, complicates the matter of you wanting to pass in a sparse list of date,price tuples. The simpliest thing to do (as mentioned above) is to first convert your sparse list of date,price tuples into a Series (with the same length and same DatetimeIndex from the original ohlc dataframe). Inside this series, the dates corresponding to your date,price tuples would have the value (price) from the tuple, and all other dates would have a value of NaN. (I think that would work; if not we can always interpolate values). If we were to take a more direct approach (similar to calling Therefore, if you want to specify just a sparse list of date,price tuples, I suggest we write a function that converts such a sparse list to a Series as described above. Then the question becomes where to call that function. One possibility is to call that function before calling
Another possibility is to call the conversion function inside If we want What do you think? As I am writing this, I am beginning to like the last proposal the best: Correction: |
Can't it work the same as plt so: |
I have no idea what you are trying to say with:
This present issue is about plotting trend lines (not a scatter plot of trades). |
@dattran2346
Will keep you posted. Have a couple other things to finish up first. |
just a note, so I don't forget; i am thinking of implementing this as a |
it doesn't work lines = []
for line_date, line_row in data.iterrows():
lines.append((line_date, line_row['signal']))
pattern_line = mpf.make_addplot(lines)
signals = mpf.make_addplot(
window['signal'], scatter=True, markersize=97)
mpf.plot(window, volume=True, type='candle',
addplot=[signals, pattern_line], style='yahoo') Raises error: Traceback (most recent call last):
File "peaks_valleys.py", line 156, in <module>
addplot=[signals, pattern_line], style='yahoo')
File "/home/putraxor/.local/lib/python3.7/site-packages/mplfinance/plotting.py", line 35, in decorator
return func(*args, **kwargs)
File "/home/putraxor/.local/lib/python3.7/site-packages/mplfinance/plotting.py", line 323, in plot
raise TypeError('apdata is list but NOT of float or int')
TypeError: apdata is list but NOT of float or int |
@putraxor - This is not implemented yet. I am almost finished with this enhancement; should be ready sometime next week. I decided to add kwargs to This is how I expect it to work: There will be three (or four) kwargs:
|
Daniel - I don't need anything - just wanted to thank you and the rest of the team for your (real-time) development. Thank you. |
@chuckf201 |
Is there anyway that I can get the matplotlib axes/figure object and add my custom plotting on top.
I currently want to draw trendlines like this
The result look like

The text was updated successfully, but these errors were encountered: