How to plot Newton's method

Don’t know if this is helpful but:

Also, see this:

1 Like

Thanks, not what I was thinking,but an interesting approach. I’ll think about it.

You might need the master version using Pkg; Pkg.add("SimplePlots#master")

I’m told that’s not a valid package name. What version of Julia are you using?

now I get

MethodError: no method matching getindex(::typeof(f), ::Int64)

Stacktrace:
 [1] (::SimplePlots.var"#16#17")(::Function) at C:\Users\Brett\.julia\packages\SimplePlots\6y94O\src\plots\plots.jl:16
 [2] plot!(::SimplePlots.SimplePlot, ::Function, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Symbol,Tuple{Real,Real},Tuple{Symbol,Symbol},NamedTuple{(:xlim, :ylim),Tuple{Tuple{Float64,Float64},Tuple{Int64,Int64}}}}) at C:\Users\Brett\.julia\packages\SimplePlots\6y94O\src\plots\plots.jl:23
 [3] plot(::Function, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Symbol,Tuple{Real,Real},Tuple{Symbol,Symbol},NamedTuple{(:xlim, :ylim),Tuple{Tuple{Float64,Float64},Tuple{Int64,Int64}}}}) at C:\Users\Brett\.julia\packages\SimplePlots\6y94O\src\plots\plots.jl:3
 [4] (::var"#21#22")(::Float64) at .\In[12]:9
 [5] top-level scope at C:\Users\Brett\.julia\packages\SimplePlots\6y94O\src\interact\gui\make_gui_block.jl:13
 [6] top-level scope at C:\Users\Brett\.julia\packages\SimplePlots\6y94O\src\interact\gui.jl:40
 [7] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

Ooops, that Plots syntax is something I have loaded privately. Add these two lines and comment out the offending one.

ts = range(a, b, length=250)
plot(ts, f.(ts), xlim=(a,b), ylim=(-5,5))
#plot(f, a, b, xlim=(a,b), ylim=(-5,5))

Back to saying scatter not deffined.

I got an eroor trying to install Simple Plots master, and instead did

(@v1.5) pkg> add SimplePlots#master

Not sure, that function is exported here: https://github.com/djsegal/SimplePlots.jl/blob/master/src/plots/plots.jl#L62

I edited the script posted earlier. Try restarting and running that entire script in a cell to make sure all the packages are loading. If that fails, you can do this with Plots and Interact in the same manner, I just thought this would be easier to get going.

still says scatter! not defined

function plot(varargs...; kwargs...)
  simple_plot = SimplePlot(; kwargs...)
  plot!(simple_plot, varargs...; kwargs...)
end

function scatter(varargs...; kwargs...)
  simple_plot = SimplePlot(; kwargs...)
  scatter!(simple_plot, varargs...; kwargs...)
end

it looks like scatter needs to be defined as a function.

Okay, I edited the script from an earlier post to use Plots + Interact. SimplePlots was only intended to make things easier. You may need to install Interact, but try the above after a restart of the kernel.

I can’t execute it in the REPL. it seems to be missing a bracket

It said I didn’t have Web IO, so I put

using WebIO
using IJulia

but it says unable to load WebIO

I’m confused. Interact runs in jupyter, not the REPL. But copy and paste should work without a syntax error.

Interact seems to run in both, the plot doesn’t run .

using WebIO

Unable to load WebIO. Please make sure WebIO works for your Jupyter client. For troubleshooting, please see the WebIO/IJulia documentation. 

Does makie allow a reaction to pressing a mouse button, or the mouse x and y locations?

It should be AbstractPlotting.scatter! (if I have Plots loaded)

Yes it does:

http://makie.juliaplots.org/stable/interaction.html

Cool! I was doing something similar in PyDev, and I would like to do it in Julia.

The example I have above in this thread (which needs updating for the newest makie, as the layout is kinda bad) shows how one can drag a point around and have the graph be reactive to that action. Something similar could be done for clicking on points. The particular example above is modified from one of the Makie examples, I think a polygon one.

2 Likes