Hi everyone,
I was trying to learn plotly thorught making a few examples, so I was trying to make a binomial tree pricing model similar to this one below.
I understood from plotly that I would use them two graphical objects as scatter, one with the vertex and the labels (prices) and the other with the edges. So far I am able to generate the graph below.
However when I try to adjust the vertical position of the vertex the plot does not change. And I canโt make the vertex and the lines more spaced. My attempt namely was on this line my_cords = [(x[0],x[1]*5) for x in my_cords]
where I tried to make them more distant vertically compared to horizontal cordinates. The plot does not change for whatever value I multiply, since plotly seems to make dome dynamical scaling that I am not aware.
my_depth = 6
my_aux = [ [0] * my_depth for x in range(my_depth) ]
counter = -1
edges = []
for i in range(my_depth):
for j in range(i+1):
counter += 1
my_aux[i][j] = counter
for i in range(my_depth-1):
for j in range(i+1):
edges.append((my_aux[i][j], my_aux[i+1][j]))
edges.append((my_aux[i][j], my_aux[i+1][j+1]))
my_graph = igraph.Graph(my_aux[~0][~0]-1, edges)
my_cords = []
my_vals = []
multiplier = 1.1
initial_val = 100
for i in range(1,my_depth+1):
current = [(i-1,x-i+1) for x in list(range(0,2*i,2))[::-1]]
my_vals = my_vals + [round(initial_val * multiplier**(-1*x[1]),2) for x in current]
my_cords = my_cords + current
my_cords = [(x[0],x[1]*5) for x in my_cords]
Xe = sum([[my_cords[y[0]][0], my_cords[y[1]][0], None] for y in [e.tuple for e in my_graph.es]], [])
Ye = sum([[my_cords[y[0]][1], my_cords[y[1]][1], None] for y in [e.tuple for e in my_graph.es]], [])
trace1 = go.Scatter(x = Xe, y = Ye, mode="lines")
trace2 = go.Scatter(x = [x[0] for x in my_cords],
y = [x[1] for x in my_cords],
mode = "markers+text",
text = my_vals,
marker=dict(symbol='square',
size=40,
color='white',
line=dict(color='rgb(50,50,50)', width=0.5)
))
myimage = go.Figure()
myimage.update_layout(plot_bgcolor='white', showlegend = False, autosize = False)
myimage.update_xaxes(visible = False)
myimage.update_yaxes(visible = False)
myimage.add_trace(trace1)
myimage.add_trace(trace2)
So I was wondering if there is some way to force a static position or some workaround to make the points appear more distant. Sorry for the silly question, but I am still trying to understand the intricacies of plotting and scalling that is done when generating the images.