Reputation: 743
I have some nodes and I want to plot them. some of them connect to others. I don't know How can I plot a line in Julia ? would you please help me?
for example a line as follow:
y=2x+5
thank you
Upvotes: 2
Views: 329
Reputation: 69869
As an addition to the answer above, actually in Plots.jl it is even simpler. Just pass a function to plot
like this:
plot(x->2x+5)
you typically will want to pass axis ranges which you can do like this:
plot(x->2x+5, xlim=(0,5), ylim=(5,15))
you can also plot several functions at once:
plot([sin, cos, x->x^2-1], label=["sin", "cos", "x²-1"], xlim=(-2,2), ylim=(-1,3))
The result of the last plotting command is:
Upvotes: 6
Reputation: 1896
Try looking at Julia's documentation about plotting as well as this tutorial found by searching Julia plots
on a web search engine.
Plotting y = 2x+5
in Julia v1.1 :
using Pkg
Pkg.add("Plots") # Comment if you already added package Plots
using Plots
plotly() # Choose the Plotly.jl backend for web interactivity
x = -5:5 # Change for different xaxis range, you can for instance use : x = -5:10:5
y = [2*i + 5 for i in x]
plot(x, y, title="My Plot")
Upvotes: 2