# How to plot specific DataFrame points?

**URL:** <https://discourse.julialang.org/t/how-to-plot-specific-dataframe-points/44922>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [August 14, 2020, 10:10am UTC](https://discourse.julialang.org/t/how-to-plot-specific-dataframe-points/44922 "2020-08-14T10:10:32Z")\
**Posts on this page:** 4\
**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 14, 2020, 10:10am UTC](https://discourse.julialang.org/t/how-to-plot-specific-dataframe-points/44922/1 "2020-08-14T10:10:32Z")

</div>

In the end I want to create a scatter plot with a specific value from columns `bb:ff` against their corresponding value in column `gg`. In my case, I have a DataFrame which I pull final simulation values out of into a new DataFrame. Is there a way to do with within a DataFrame or should I convert it to a different format? I’ll probably need a way of pulling out the specific values into a `Vector` or something, to be able to create a scatter plot in the end. Any help or advice is appreciated

```julia
asdf = DataFrame(bb = 10 .* rand(6),
cc = 10 .* rand(6),
dd = 10 .* rand(6),
ee = 10 .* rand(6),
ff = 10 .* rand(6),
gg = 10 .* rand(6))

```

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

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 14, 2020, 10:32am UTC](https://discourse.julialang.org/t/how-to-plot-specific-dataframe-points/44922/2 "2020-08-14T10:32:31Z")

</div>

Assuming that your dataframe has `n` rows and `n+1` columns (note that the code you posted gives a 6x6 DataFrame, but your screenshot suggests 5x6), you can do:

```julia
using LinearAlgebra
scatter(diag(Matrix(asdf[:, 1:end-1])), asdf[!, end])

```

This will create a square matrix from the first `n` columns and take the diagonal to create the `x` vector and then take the last column as the `y` vector.

---

<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 14, 2020, 11:30am UTC](https://discourse.julialang.org/t/how-to-plot-specific-dataframe-points/44922/3 "2020-08-14T11:30:19Z")

</div>

Thank you for your reply.  
`diag` is undefined for me, is it part of a package? The package `LinearAlgebra` needs to be added and run.

This is much simpler than what I was trying to use

`target_biomass = map(x -> asdf[x, Int.(asdf[:, :gg].+1)[x]], 1:size(asdf, 1))` and was getting

```julia

InexactError: Int64(7.033957373089748)
in include_string at base\loading.jl:1088
in top-level scope at untitled:27
in map at base\abstractarray.jl:2162
in collect_similar at base\array.jl:628
in _collect at base\array.jl:699
in iterate at base\generator.jl:47 
in at untitled:27
in materialize at base\broadcast.jl:837
in copy at base\broadcast.jl:862 
in copyto! at base\broadcast.jl:886 
in copyto! at base\broadcast.jl:931 
in macro expansion at base\simdloop.jl:77 
in macro expansion at base\broadcast.jl:932 
in getindex at base\broadcast.jl:575 
in _broadcast_getindex at base\broadcast.jl:621 
in _broadcast_getindex_evalf at base\broadcast.jl:648 
in Int64 at base\float.jl:710 

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 14, 2020, 12:07pm UTC](https://discourse.julialang.org/t/how-to-plot-specific-dataframe-points/44922/4 "2020-08-14T12:07:45Z")

</div>

Yes sorry, `diag` is in the `LinearAlgebra` standard library, have editet the above to make it an MWE. Glad it worked!
