# How to plot different series from an array

**URL:** <https://discourse.julialang.org/t/how-to-plot-different-series-from-an-array/27843>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [August 22, 2019, 1:20pm UTC](https://discourse.julialang.org/t/how-to-plot-different-series-from-an-array/27843 "2019-08-22T13:20:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [August 22, 2019, 1:20pm UTC](https://discourse.julialang.org/t/how-to-plot-different-series-from-an-array/27843/1 "2019-08-22T13:20:42Z")

</div>

Hello, I am using Atom on a Windows 10 and I have an array named `final_output_array` with three columns which looks like (but without column titles in Atom and blue added for ease of reading)

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

And I want to make it look like

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

I am not sure how to specify the series(species harvested) for the legend. I think it could be

```julia
labels = [final_array_output[1:5,1]] #here I think I need to specify [1,1] [6,1][11,1][16,1][21,1]
plot(final_array_output, xaxis=final_array_output[1:5,1, yaxis=final_array_output[1:5,3], label = labels)

```

Made up data for array

```julia
[1 1 12.34;2 1 45.32;3 1 23.4;4 1 56.43;5 1 90.2;1 2 45.3;2 2 76.2;3 2 72.3;4 2 72.6;5 2 30.2;1 3 53.2;2 3 42.3;3 3 94.1;4 3 23.0;5 3 19.2;1 4 20.3;2 4 30.2;3 4 98.2;4 4 53.9;5 4 83.7]

```

---

<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:** [August 22, 2019, 4:59pm UTC](https://discourse.julialang.org/t/how-to-plot-different-series-from-an-array/27843/2 "2019-08-22T16:59:05Z")

</div>

Hm… the data matrix looks complex, so I’m trying to divide up the problem. Assuming that your example data has 5 Species (1,…,5) and 4 Species harvested (1,…,4), I’m doing the following:

```julia
using Plots; pyplot();
data = [1 1 12.34;2 1 45.32;3 1 23.4;4 1 56.43;5 1 90.2;1 2 45.3;2 2 76.2;3 2 72.3;4 2 72.6;5 2 30.2;1 3 53.2;2 3 42.3;3 3 94.1;4 3 23.0;5 3 19.2;1 4 20.3;2 4 30.2;3 4 98.2;4 4 53.9;5 4 83.7];
fg = plot();
for sh in 1:4
    idx_sh = data[:,2] .== sh
    plot!(fg,data[idx_sh,1], data[idx_sh,3], lw=2,label="Species $(sh) harvested")
end
plot!(fg,xlabel="Species", "Biomass")

```

leads to:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/2/42be96fbf7fbbe731121ecbfcea60bfb268cd789.png)

A handful of comments.

- By first doing `fg = plot()`, I create an empty plot pane and name it `fg` (my abbreviation for “fig”).
- Next, statement `plot!(fg,...)` adds plot commands to the plot pane, which is nice in a loop.
- In your indication of what the plot should look like, my interpretation is that you want the Species number (integer in range 1:5 in the given data) as abscissa (“x axis”) and Biomass (real number) as ordinate (“y axis”), with Species harvested (integer in range 1:4 in the given data) as parameter.
- … so first I find the index of the rows that hold data for Species harvested no. 1, 2, 3, etc. (`idx_sh = data[:,2] .== sh` – or: the Index of Species harvested (`idx_sh`) where `data` in column `2` equals the Species harvested (`sh`) loop variable
- … next, I plot the mapping `data[idx_sh,1]` vs. `data[idx_sh,3]`, i.e., Species vs. Biomass in turn for parameter `sh`.
- After the loop is finished, I add abscissa and ordinate labels (`xlabel`, `ylabel`). Note that the plot doesn’t show unless you do an explicitly `plot(fg,...)` command after the loop.

You can add niceties such as plot title, specify color of lines, etc., if you don’t like the default colors, etc.
