Is there an easy way to just add a line to a plot by specifying the slope and intercept in the current diagram’s x/y coordinates?
I know one can do this by adding a scatter trace with line mode and either finding the min/max (x,y) points or just adding the ys for all the xs one has for the line, but in some cases all one has is the slope and intercept and doing this “manually” every time is just such a waste of time.
‘manual’ ? - there is no paper and pencil involved in the response above. it is written in python code.
the idea was not to complete the plot in matplotlib, but to modify the function in a relatively simple way to produce the points that constitute the straight line, defined by slope and intercept, within the upper and lower x-bounds of the data set.
once the pair of (x, y) points are defined, they can be added as a line to whatever scatter plot is otherwise begin generated.
slight modification to above function can likely be made to produce a single line re-usable method call.
This is what I already know: plotting line segments for each value in x which seems like a really bad way to do it.
Other plot libraries have an abline method which will simple add the necessary line using the only two parameters needed: intercept and slope, not require to calculate an x/y pair for each point in the graph.
Sorry for the late reply, I did not use plotly for quite a while.
I have not seen a concise method for this so far, sadly. I think it is really absurd that such a basic tool is not present. Drawing a line by slope and intercept should be embarrassingly easy to implement really