# Assign x values is plots

**URL:** <https://discourse.julialang.org/t/assign-x-values-is-plots/48516>\
**Category:** General Usage\
**Created:** [October 16, 2020, 7:58pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516 "2020-10-16T19:58:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 16, 2020, 7:58pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/1 "2020-10-16T19:58:32Z")

</div>

```julia
using Roots
using Plots

J=f(x)=x^2+10sin(x)
g(x)=f(x)-1000
find_zeros(g,0,10000)

plot(J)

```

The above works fine, but I want to plot a horizontal line at 1000, and plot J, so that x goes from 0 to 100. I’m not sure from the documentation, how to assign 0 values

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [October 16, 2020, 8:05pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/2 "2020-10-16T20:05:33Z")

</div>

something like

```julia
using Roots
using Plots

J=f(x)=x^2+10sin(x)
g(x)=f(x)-1000
find_zeros(g,0,10000)

plot(J, 0, 100)
hline!([1000])

```

?  
I’m not really sure, what you mean by

> how to assign 0 values

Assign them to what?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 16, 2020, 8:12pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/3 "2020-10-16T20:12:32Z")

</div>

to x, I want to assign a range of 0, 100 to x, so that it shows x for that range. Which is exactly what you provided! Thanks!

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 16, 2020, 8:56pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/4 "2020-10-16T20:56:13Z")

</div>

Nice function `find_roots`.

You don’t need to name the function by `J`, unless there is another reason for introducing it.

I played with a modification of your problem:

```julia
using Plots, LaTeXStrings, Roots
f(x) = (x/4)^2 +10sin(x+pi/3)
g(x) = (x/5)^2
h(x) = f(x)-g(x)
xr = find_zeros(h,0,20)
#
hline(f.(xr),lw=4,lc=:orange,la=0.15,label="")
vline!(xr,lw=4,lc=:orange,la=0.15,label="")
plot!(f,0,20,lw=3,lc=:cornflowerblue,label=L"f(\cdot)")
plot!(g,0,20,lw=3,lc=:crimson,label=L"g(\cdot)")
scatter!(xr,f.(xr),ms=7,mc=:orange,label="roots",legend=:topleft)

```

which produces:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/1/61380a9fda33449bbbb377cd6a3e9af2aa6afe80.png)

Julia is nice :-). I love the support of html colors, see, e.g., [HTML Color Names](https://www.w3schools.com/colors/colors_names.asp) .

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 16, 2020, 9:31pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/5 "2020-10-16T21:31:07Z")

</div>

I thought I dod for plots, but it looks like you assign values for plots. I like the graph, but the big thing is to show that since f(x) is continuous, there is value for every point, even irrationals, like sqrt(1000)

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 16, 2020, 9:32pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/6 "2020-10-16T21:32:42Z")

</div>

What is LaTexStrings? I think I need to work more with LaTex, I’ve gotten handy with the equation functions in Word.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 16, 2020, 9:54pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/7 "2020-10-16T21:54:55Z")

</div>

> [@brett\_knoss](#):
>
> I thought I dod for plots, but it looks like you assign values for plots. I like the graph, but the big thing is to show that since f(x) is continuous, there is value for every point, even irrationals, like sqrt(1000)

It’s not clear what you want to show. Could you please be more specific?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 16, 2020, 9:55pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/8 "2020-10-16T21:55:59Z")

</div>

Just the that that f is the function f(x) when plotting. I changed it in Julia afterwards.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 17, 2020, 3:21pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/9 "2020-10-17T15:21:23Z")

</div>

Package `LaTeXStrings` allows for a modifier (`L`) placed in front of strings (`"..."`), e.g., `L"..."`, which inserts some \LaTeX code and makes it simpler to construct strings with math. So I can write `L"f(\cdot)"` which the `LaTeXStrings` package changes to the appropriate string of \LaTeX code.

To appreciate `LaTeXStrings`, you need to find a book on \LaTeX/\TeX math, and study the documentation of `LaTeXStrings`.

`LaTeXStrings` is not perfect, essentially because \LaTeX uses symbol `$` to bracket math, while `$` is simultaneously used in Julia as “interpolator” in text strings. I don’t have any perfect solution to this, though.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [October 17, 2020, 3:33pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/10 "2020-10-17T15:33:10Z")

</div>

You want the function `nameof` giving the name of a function

```julia
julia> function g(x)
       x + 1
       end
g (generic function with 1 method)

julia> function myplot(fun, x)
           plot(fun.(x), label = string(nameof(fun)))
       end
myplot (generic function with 1 method)

julia> x = [1, 2, 3];

julia> myplot(g, x)

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [October 17, 2020, 9:31pm UTC](https://discourse.julialang.org/t/assign-x-values-is-plots/48516/11 "2020-10-17T21:31:06Z")

</div>

Yes, I want to study LaTex, but I’m in a rush to study everything.
