# Polynomial plot clipped?

**URL:** <https://discourse.julialang.org/t/polynomial-plot-clipped/73747>\
**Category:** General Usage\
**Tags:** plotting, plots, polynomials, recipe\
**Created:** [December 29, 2021, 6:33am UTC](https://discourse.julialang.org/t/polynomial-plot-clipped/73747 "2021-12-29T06:33:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulmelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmelis/32/35063_2.png) [@paulmelis](https://discourse.julialang.org/u/paulmelis)\
**Post date:** [December 29, 2021, 6:33am UTC](https://discourse.julialang.org/t/polynomial-plot-clipped/73747/1 "2021-12-29T06:33:12Z")

</div>

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

```julia
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)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/4/8/487f0768751c57ba02281a3728ab25cc723ad842.png)

```julia
julia> f(4)
1.0567615925524965

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

```

![image](https://global.discourse-cdn.com/julialang/original/3X/4/a/4ab0b78d029241d83df12660be38d258fbb7001d.png)

```julia
(@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

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 29, 2021, 8:25am UTC](https://discourse.julialang.org/t/polynomial-plot-clipped/73747/2 "2021-12-29T08:25:15Z")

</div>

If we perform a standalone `plot(f)` and [read here](https://github.com/JuliaMath/Polynomials.jl/blob/f0ed210c1ac83bc91172e9c2314838a83f5439cd/docs/src/reference.md#plotting) 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.

---

<div class="post-metadata">

**Author:** ![paulmelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmelis/32/35063_2.png) [@paulmelis](https://discourse.julialang.org/u/paulmelis)\
**Post date:** [December 29, 2021, 10:49am UTC](https://discourse.julialang.org/t/polynomial-plot-clipped/73747/3 "2021-12-29T10:49:26Z")

</div>

> [@rafael.guerra](#):
>
> If we perform a standalone `plot(f)` and [read here](https://github.com/JuliaMath/Polynomials.jl/blob/f0ed210c1ac83bc91172e9c2314838a83f5439cd/docs/src/reference.md#plotting) about the plot recipe for polynomials, one can make sense out of this.

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](https://juliamath.github.io/Polynomials.jl/stable/#Fitting-arbitrary-data) I based my own code on, the `extrema(xs)...` argument was also a hint, but still. Too much surprise for my liking.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 29, 2021, 11:50am UTC](https://discourse.julialang.org/t/polynomial-plot-clipped/73747/4 "2021-12-29T11:50:58Z")

</div>

The question is above my skill level, but I was surprised to see the following command coming back empty handed:  
`methodswith(typeof(f))`

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 29, 2021, 1:07pm UTC](https://discourse.julialang.org/t/polynomial-plot-clipped/73747/5 "2021-12-29T13:07:32Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [December 29, 2021, 5:30pm UTC](https://discourse.julialang.org/t/polynomial-plot-clipped/73747/6 "2021-12-29T17:30:19Z")

</div>

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