# Plot series data by Plots

**URL:** <https://discourse.julialang.org/t/plot-series-data-by-plots/35377>\
**Category:** General Usage\
**Tags:** question, plotting, plots\
**Created:** [March 1, 2020, 10:35pm UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377 "2020-03-01T22:35:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [March 1, 2020, 10:35pm UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377/1 "2020-03-01T22:35:56Z")

</div>

Hi commuinty,  
Q1: Is there a way to use x, y and legend (as below) to plot data in series?  
#y matrix: row corresponding to each x value, column for each series (marked by legend) of data

```julia
x=[2 4 6 8 10 12]#corresponding to each row
y= [10.6667 10.3333 8.0 14.6667;
   10.0 7.33333 7.66667 17.0;   
    8.0 7.33333 8.33333 12.0;   
    4.33333 5.33333 7.33333 11.3333;
    4.66667 4.0 4.0 10.6667;
    4.33333 3.33333 4.0 12.0]

legend=["a" "b" "c" "d"] #each series-column
using Plots
#expected points distribution as like:
plot(y,legend) #but x and legend not accordingly specified

#trial1:
for i in 1:4 #for 4 series
   if i==1
      plot(x,y[:,i],label=legend[i])
   else
      plot!(x,y[:,i],label=legend[i])
   end
end #not generating any graph

```

According to  
[http://docs.juliaplots.org/latest/examples/gr/#functions-adding-data-and-animations](http://docs.juliaplots.org/latest/examples/gr/#functions-adding-data-and-animations)

```julia
#trial2
for i in 1:4 #for 4 series
   if i==1
      p=plot(x,y[:,i],label=legend[i])
   else
      push!(p,x,y[:,i])#,label=legend[i] #not work probably as not animation?
   end
end

```

Q2: Also, within a for loop, scatter(,label=legend[i]) tend to replicate the mark of i-th legend the number of row times. This post was discussing about the same problem, but the suggested commands to avoid replication seems not compiled, while the one for animation (in trial2) doesn’t work as well.

> [@Plots: Only one series as primary plot](https://discourse.julialang.org/t/plots-only-one-series-as-primary-plot/24616/7):
>
> Yeah Plots certainly doesn’t make it impossible for me, it’s just that all available alternatives are awkward and verbose confused

---

<div class="post-metadata">

**Author:** ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)\
**Post date:** [March 1, 2020, 11:20pm UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377/2 "2020-03-01T23:20:27Z")

</div>

EDIT: @BLI 's solution is better

---

<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:** [March 1, 2020, 11:23pm UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377/3 "2020-03-01T23:23:07Z")

</div>

Is this what you want?

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

If so, make `x` a vector, and not a row matrix:

```julia
x=[2, 4, 6, 8, 10, 12]#corresponding to each row

```

---

<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:** [March 1, 2020, 11:49pm UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377/4 "2020-03-01T23:49:54Z")

</div>

you need a package, I used Plots

```julia
using Plots

```

type that, you’ll get an error

```julia
ERROR: ArgumentError: Package boogers not found in current path:
- Run `import Pkg; Pkg.add("Plots")` to install the Plots package.

```

just highlight

```julia
import Pkg; Pkg.add("Plots")

```

then renter ‘using Plots’, any you’ll be set

then to make a line graph just enter

```julia
plot(x,y,)

```

I’d give my dataplot a name like “z”

```julia
z= dataframe( x=[2 ,4, 6, 8, 10, 12], y= [10.6667, 10.3333, 8.0, 14.6667, 10.0])

then enter 

```

plot(z.x, z.y)

```julia

```

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [March 2, 2020, 12:01am UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377/5 "2020-03-02T00:01:39Z")

</div>

Exactly, thank you！

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [March 2, 2020, 12:03am UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377/6 "2020-03-02T00:03:14Z")

</div>

This would be helpful for dataframes, thank you.

---

<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:** [March 2, 2020, 12:12am UTC](https://discourse.julialang.org/t/plot-series-data-by-plots/35377/7 "2020-03-02T00:12:28Z")

</div>

Sure thing, also sorry for overexplaing stuff like how to add packages, I have a tendency to jump in without completely reading things.
