Polynomial plot clipped?

Curious, why does the plot of f get clipped around x=5.5?

julia> using Plots, Polynomials
julia> xdata = [1.0, 3.5, 5.5, 7.0]
julia> ydata = [1.6884409261691142, 1.1095511387771335, 0.9753592108946215, 0.9522272216874024]

julia> f = fit(xdata, ydata)
Polynomial(2.117795572338809 - 0.4985750122785805*x + 0.07285077836751414*x^2 - 0.0036304122586283856*x^3)

julia> plot(f, xlim=(1,7), ylim=(0,3), legend=false)


julia> f(4)

julia> g(x) = 2.117795572338809 - 0.4985750122785805*x + 0.07285077836751414*x^2 - 0.0036304122586283856*x^3
g (generic function with 1 method)


(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [c7e460c6] ArgParse v1.1.4
  [6e4b80f9] BenchmarkTools v1.2.2
  [fa961155] CEnum v0.4.1
  [3da002f7] ColorTypes v0.11.0
  [864edb3b] DataStructures v0.18.11
  [53c48c17] FixedPointNumbers v0.8.4
  [a09fc81d] ImageCore v0.9.3
  [82e4d734] ImageIO v0.5.9
  [682c06a0] JSON v0.21.2
  [0f8b85d8] JSON3 v1.9.2
  [2fda8390] LsqFit v0.12.1
  [5fb14364] OhMyREPL v0.5.10
  [91a5bcdd] Plots v1.25.3
  [c3e4b0f8] Pluto v0.17.3
  [f27b6e38] Polynomials v2.0.20
  [c46f51b8] ProfileView v1.0.1
  [a8a75453] StatProfilerHTML v1.0.0
  [90137ffa] StaticArrays v1.2.13
  [b8865327] UnicodePlots v2.5.1
  [aacddb02] JpegTurbo_jll v2.1.0+0

If we perform a standalone plot(f) and read here about the plot recipe for polynomials, one can make sense out of this.

It’s odd that the xlim=(1,7) argument must be replaced by the alternative syntax: plot(f, 1, 7); while ylim added to that does work though.

1 Like

Hmm, other than thinking of looking in the Polynomials.jl documentation is there any method I could have used in the REPL to notice it was using a different plot function? I.e. ? plot doesn’t list the other form.

Edit: looking more closely at the example I based my own code on, the extrema(xs)... argument was also a hint, but still. Too much surprise for my liking.

1 Like

The question is above my skill level, but I was surprised to see the following command coming back empty handed:

Just in case, in order to not rely on the polynomials type recipe and avoid surprises, one could use an anonymous function:

plot(x -> f(x), xlim=(1,7), ylim=(0,3), legend=false)
1 Like

This should be fixed with the just tagged v2.0.21.