I need to find (print) points of a plot that are 50% lower and upper of a trend line using Python and preferably using Plotly. I could make so far a trend line of a positive linear trend using plotly.
I want to get something like this graph that I found here:
Since you haven't provided a dataset, I'm going to build a solution based on an earlier answer of mine: Plotly: How to add trendline and parallel lines to time series data?. And here's the resulting plot for your use case:
I can't guarantee that the dotted lines are 100% what you're looking for, since it will be a matter of opinion how your desired lines should be calculated. What I've done here is simply finding which values lie above the trend line, take the average, and add that average to the constant term when calculating the accompanying
top 50 %
line in:But using the average only makes real sense if the points are somewhat evenly distributed over the trend line. And as far as I know, you may prefer to count half of the values over the trend line, and make a line there. But I'll leave that for you to decide. Anyway, if your end goal is to mark or highlight thosw points, the code snippet below will let you end up with this:
I hope you'll find this suggestion useful. And please don't hesitate to let me know if anything is unclear.
Complete code with sample data