# Unable to make multiple lines in Plots

**URL:** https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401
**Category:** General Usage
**Tags:** plotting
**Created:** [November 1, 2020, 7:17am UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401 "2020-11-01T07:17:11Z")
**Posts on this page:** 8
**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: [November 1, 2020, 7:17am UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/1 "2020-11-01T07:17:11Z")

</div>

I tried to plot 2 lines on the same graph

```julia
using Plots

f(x)=x^2
d(x)=2x

plot(f)
plot!(d)

```

But when I try to run this I get an error.

```julia
ERROR: UndefVarError: plot! not defined
Stacktrace:
 [1] top-level scope at REPL[673]:1

```

Do I have all the right packeges? Do I have the right syntax? including comas and semicolons?

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [November 1, 2020, 7:37am UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/2 "2020-11-01T07:37:18Z")

</div>

> [@brett\_knoss](#):
>
> ```julia
> using Plots
> 
> f(x)=x^2
> d(x)=2x
> 
> plot(f)
> plot!(d)
> 
> ```

Using Julia 1.5.0 the code works fine:

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

Perhaps try `] update`. The “]” is important it lets you enter “pkg” mode. Then backspace to leave it afterwards. If it still does not work, try:

```julia
using Pkg
Pkg.rm("Plots")
Pkg.add("Plots")

```

Kind regards

---

<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: [November 1, 2020, 5:53pm UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/3 "2020-11-01T17:53:45Z")

</div>

I might try that. A thing came up on VS Code, saying indexing packages, and now I can’t seem to add new packages, or start. packages. I can’t do one plot now. I just get an error.

```julia
julia> plot(f)
ERROR: error compiling _plot!: error compiling _display: could not load library "libGR.dll"
The specified module could not be found.

Stacktrace:
 [1] #plot#131(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(plot), ::Function) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\plot.jl:57
 [2] plot(::Function) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\plot.jl:51
 [3] top-level scope at REPL[3]:100:

```

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [November 1, 2020, 5:56pm UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/4 "2020-11-01T17:56:27Z")

</div>

You have to build GR, try:

```julia
using Pkg
Pkg.build("Plots")
Pkg.build("GR")

```

Kind regards

---

<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: [November 1, 2020, 6:55pm UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/5 "2020-11-01T18:55:45Z")

</div>

Awesome! It all seems to work now. Now how do I add a horizontal line?

when I add:

```julia
hline!(1)

```

I get :

```julia
hline!(1)
ERROR: BoundsError: attempt to access 0-element Array{Float64,1} at index [1]
Stacktrace:
 [1] getindex(::Array{Float64,1}, ::Int64) at .\array.jl:744
 [2] expand_extrema!(::Plots.Subplot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\axes.jl:350
 [3] _expand_subplot_extrema(::Plots.Subplot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict, ::Symbol) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\pipeline.jl:361        
 [4] add_series!(::Plots.Plot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\pipeline.jl:312
 [5] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict) at C:\Users\Brett\.julia\packages\RecipesPipeline\tkFmN\src\series_recipe.jl:44
 [6] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict) at C:\Users\Brett\.julia\packages\RecipesPipeline\tkFmN\src\series_recipe.jl:58
 [7] _process_seriesrecipes!(::Plots.Plot{Plots.GRBackend}, ::Array{Dict{Symbol,Any},1}) 
at C:\Users\Brett\.julia\packages\RecipesPipeline\tkFmN\src\series_recipe.jl:25
 [8] recipe_pipeline!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Int64}) 
at C:\Users\Brett\.julia\packages\RecipesPipeline\tkFmN\src\RecipesPipeline.jl:96        
 [9] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{Int64}) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\plot.jl:167
 [10] #plot!#136(::Base.Iterators.Pairs{Symbol,Symbol,Tuple{Symbol},NamedTuple{(:seriestype,),Tuple{Symbol}}}, ::typeof(plot!), ::Plots.Plot{Plots.GRBackend}, ::Int64) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\plot.jl:158
 [11] (::RecipesBase.var"#kw##plot!")(::NamedTuple{(:seriestype,),Tuple{Symbol}}, ::typeof(plot!), ::Plots.Plot{Plots.GRBackend}, ::Int64) at .\none:0
 [12] #plot!#135(::Base.Iterators.Pairs{Symbol,Symbol,Tuple{Symbol},NamedTuple{(:seriestype,),Tuple{Symbol}}}, ::typeof(plot!), ::Int64) at C:\Users\Brett\.julia\packages\Plots\uCh2y\src\plot.jl:150
 [13] (::RecipesBase.var"#kw##plot!")(::NamedTuple{(:seriestype,),Tuple{Symbol}}, ::typeof(plot!), ::Int64) at .\none:0
 [14] #hline!#378 at C:\Users\Brett\.julia\packages\RecipesBase\aQmWx\src\RecipesBase.jl:403 [inlined]
 [15] hline!(::Int64) at C:\Users\Brett\.julia\packages\RecipesBase\aQmWx\src\RecipesBase.jl:403
 [16] top-level scope at REPL[14]:1

```

---

<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: [November 1, 2020, 7:29pm UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/6 "2020-11-01T19:29:01Z")

</div>

try `hline!([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: [November 1, 2020, 7:36pm UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/7 "2020-11-01T19:36:52Z")

</div>

Yup, lol. I should have found that. I don’t see anything though about changing the spacing of x

```julia
using Plots
f(x)=x^2
plot(1:10,f)

```

I get jagged lines, I’d like to know if i can make the line smoother, or if I need to change the backend to do that.

---

<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: [November 1, 2020, 7:38pm UTC](https://discourse.julialang.org/t/unable-to-make-multiple-lines-in-plots/49401/8 "2020-11-01T19:38:49Z")

</div>

just use a more fine-grained `x`, like `plot(range(0, 1, length = 1000), f)`
