Hi, I am having great difficulty in getting a regression line to be drawn on the same figure as a scatter trace. I am just really puzzled because there is nothing complicated here, and I am following quite closely with the line and scatter examples.
Here is the code that I am trying to use to generate the plot:
datapts = go.Scatter(x = data["Population"], y=data["Profit"], mode = "markers",
hoveron = "points")
reg_line = go.Scatter(x = pop_range, y = profit_predicted, mode = "lines",
hoveron="points")
plotly.offline.iplot({
"data": [datapts,reg_line],
"layout": go.Layout(title="Relationship between Population and Profit", xaxis = dict(title="Population of City in 10,000s"),
yaxis = dict(title="Profit in $10,000s"))
})
The figure generated just looks like:
As you can see, the line, trace 1, just does not show up at all. To make it possible to help me, these are what the arrays look like:
data["Population"][0:5] # 97 elements long
0 6.1101
1 5.5277
2 8.5186
3 7.0032
4 5.8598
Name: Population, dtype: float64
data["Profit"][0:5] # 97 elements long
0 17.5920
1 9.1302
2 13.6620
3 11.8540
4 6.8233
Name: Profit, dtype: float64
pop_range[0:5] # 100 elements long
array([ 5.0269 , 5.20039596, 5.37389192, 5.54738788, 5.72088384])
profit_predicted[0:5] # 100 elements long
matrix([[ 2.23289546],
[ 2.43525461],
[ 2.63761377],
[ 2.83997293],
[ 3.04233208]])
I’m at my wits end. I’ve tried casting the profit_predicted
matrix to a 1 dimensional flattened numpy array, but the bug does not go away, so I really do not know what’s the cause here.
Thank you.