Gwalchaved
Gwalchaved

Reputation: 142

python-plotly : add a scatter using x0/dx and y0/dy

after reading plotly's reference, I understood that rather than giving a list of point to draw a line, I could just give a point of origin and steps for x and y axes.

Then I tried this pretty basic first attempt:

import plotly.graph_objects as go
f = go.Figure()
f.add_trace(go.Scatter(x0=1, dx=1, y0=2, dy=1))
f.show(renderer='browser')

A browser window opens with a graph in it, but it is void. And I get no error message. Surprisingly, I found nothing online to help me.

Can someone tell me what I'm doing wrong, or what I don't understand from Plotly's reference ? Thanks for your time and help.

Upvotes: 0

Views: 1462

Answers (1)

nicolaskruchten
nicolaskruchten

Reputation: 27370

So this is a bit confusing in the docs, but the x0/dx pattern only works if you're providing y(and vice versa y0/dy only makes sense if you're providing x). They're basically shortcuts for providing data-free vectors.

For example:

import plotly.graph_objects as go
fig = go.Figure(go.Scatter(x0=10, dx=2, y=[1,3,2,4]))
fig.show()

is equivalent to providing x=[10,12,14,16] instead of x0/dx, but only in the presence of y.

To draw a straight line, you can use the layout.shapes API like this:

fig.update_layout(shapes=[dict(type="line", x0=11, x1=14, y0=3, y1=4)])

Upvotes: 3

Related Questions