Ignasi
Ignasi

Reputation: 631

Plotly Draw line according to an equation

I would like to drow a line according to an equation, for example: y=2x+3.

Is there any way to do this in plotly javascript (or python) without having to sample the equation at different points?

Upvotes: 3

Views: 5135

Answers (1)

Ilya V. Schurov
Ilya V. Schurov

Reputation: 8087

No, it is not possible in the way you are asking for. plotly just visualizes some arrays of data and these arrays can be obtained in different ways: e.g. by querying some database or by calculating with equation. But if you want to use equation, you have to calculate appropriate x and y arrays (or x, y and z in case of 3D plots) and then send it to plotly.

Here is example in Python (Jupyter Notebook):

from plotly.offline import init_notebook_mode, iplot
import numpy as np
init_notebook_mode()

x = np.linspace(-2, 3)
iplot([{'x': x, 'y': x**2}])

Parabola

If this is inappropriate way to do this for you, I believe it worth to expand a question and explain why.

Upvotes: 3

Related Questions