Open Baappii opened 2 years ago
Adding data to a renko plot is very tricky. This is because renko calculations result in both (1) a non-linear time axis, and (2) fewer points on the time axis than there are rows in the dataframe.
One possible workaround may be to use the return_calculated_values
kwarg. You must first create a variable that contains an empty dictionary, and then pass this variable in with the return_calculated_values
kwarg:
cvals = {}
fig, axlist = mpf.plot(data,type=renko,...,return_calculated_values=cvals,returnfig=True)
As shown above, do this also with the returnfig=True
kwarg.
You can then examine the values returned in the cvals
dictionary to see how many renko bricks were ploted along the x-axis, and to see what the datetime values are for those bricks. Then, using the same datetime values, you can create a scatter plot on one of the axes objects in the returned axlist
.
@DanielGoldfarb thank you for you kind input. I was just running into wall, Your explanation makes easy for me to understand whole concept. My only question would be is there a sample code as ref on how to plot scatter plot using "axlist". can this axlist(scatter points) displayed in same panel as renko chart. As i was not able to addplot to renko previously. appreciate your time.
@Baappii
This page here (returnfig=True
) explains how you can determine which axes object in the axlist
that is returned by plot (in terms of which list item corresponds to the axes objects for each panel). So by choosing the appropriate axlist[item]
you can put the scatter plot on whichever panel you want.
Then it is just a matter of calling matplotlib's Axes.scatter()
(for example, as axlist[item].scatter()
).
The x-values passed into scatter()
are tricky: for renko, the x-values will need to be the row number of the corresponding datetimes returned by return_calculated_values
. (You can see how the renko code does this here). I am 99% sure that is the correct way to do it, but let me know if there is a problem.
Keep in mind, since you are using returnfig=True
then you may need to call mpf.show()
when you are done manipulating things and you are ready to display your plot. All the best. -Daniel
@Baappii
Have you had any luck with this?
--Daniel
@DanielGoldfarb ... thank you for your wonderful work.
Hello can someone help me to add scatter points to my renko chart. All i am trying to do is add scatter chart to existing chart(ie marker) "o" where volume is > 500 in my data.
sample Data structure - csv file:
Basic code:
current sample image: