# Showing plots within DataFrames.jl + Plots.jl

**URL:** <https://discourse.julialang.org/t/showing-plots-within-dataframes-jl-plots-jl/52708>\
**Category:** Visualization\
**Tags:** plotting, dataframes\
**Created:** [January 1, 2021, 7:32pm UTC](https://discourse.julialang.org/t/showing-plots-within-dataframes-jl-plots-jl/52708 "2021-01-01T19:32:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![delnatan](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@delnatan](https://discourse.julialang.org/u/delnatan)\
**Post date:** [January 1, 2021, 7:32pm UTC](https://discourse.julialang.org/t/showing-plots-within-dataframes-jl-plots-jl/52708/1 "2021-01-01T19:32:51Z")

</div>

Hi everyone!

I was playing around with Pluto.jl and found that you can display individual plots stored in a column within a DataFrame. This is pretty cool!  
For example:

```julia
using Plots
using DataFrames

arrplots = [
	plot(1:10, rand(10), legend=false, size=(180,95)) for i in 1:3
];

dfplots = DataFrame(id=1:3, plots=arrplots)

```

However, when using the Jupyter notebook each plots just gets displayed with its type (e.g. `Plot{Plots.GRBackend() n=1}`).

Are there examples for how to implement a custom `show()` method within the Jupyter notebook to show the plots rather than the type? it would be cool to get the same view as in Pluto.jl.

Thanks!

-Daniel

---

<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:** [January 1, 2021, 11:11pm UTC](https://discourse.julialang.org/t/showing-plots-within-dataframes-jl-plots-jl/52708/2 "2021-01-01T23:11:21Z")

</div>

I don’t think this would be that easy. You can take a look at PrettyTables.jl (the backend for DataFrames printing) to see what exact method is called when printing.

But best would be to just write your own function for showing the plots in a data frame of plots.

---

<div class="post-metadata">

**Author:** ![delnatan](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@delnatan](https://discourse.julialang.org/u/delnatan)\
**Post date:** [January 2, 2021, 4:20pm UTC](https://discourse.julialang.org/t/showing-plots-within-dataframes-jl-plots-jl/52708/3 "2021-01-02T16:20:00Z")

</div>

PrettyTables look awesome! i’ll take a look at it. Thanks!

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [January 2, 2021, 5:43pm UTC](https://discourse.julialang.org/t/showing-plots-within-dataframes-jl-plots-jl/52708/4 "2021-01-02T17:43:36Z")

</div>

This sounds to me like an unexpected surprise rather than something I’d expect to actually work. When I was doing a lot of plotting in Jupyter, I remember just calling `display` on plots that were created in the same cell. You could maybe just broadcast `display` over the vector of plots?

---

<div class="post-metadata">

**Author:** ![delnatan](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@delnatan](https://discourse.julialang.org/u/delnatan)\
**Post date:** [January 2, 2021, 6:17pm UTC](https://discourse.julialang.org/t/showing-plots-within-dataframes-jl-plots-jl/52708/5 "2021-01-02T18:17:43Z")

</div>

I did try broadcasting `display` over the vector of plots (e.g. `display.(arrplots)`) and it works. I’m not sure how to do this with a DataFrame so I can display all of the columns.

I did play around with PrettyTables.jl as pdeffebach pointed to before and found workablesolution (although not displaying inline) using `pretty_table` and output to a HTML file.

```julia
using DataFrames
import PrettyTables

# kind of a hack to deal with a `Plot`. The `show()` method for a MIME("text/html") has newlines in it
function PrettyTables._parse_cell_html(cell::Plots.Plot{Plots.GRBackend}; kwargs...)
    replace(sprint(show, MIME("text/html"), cell),"\n"=>"")
end

arrplots = [
    plot(1:10, rand(10), size=(170,95), legend=false) for _ in 1:3
]

df = DataFrame(:A => rand(3), :B => arrplots)

open("plot_output.html", "w") do f
   PrettyTables.pretty_table(f, df, backend = :html, renderer = :show)
end

```

I got the following output:

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

I’ve mostly been working in Python in the past few years… but my recent experience working in Julia has been a lot of fun because of little things like this. It probably would’ve taken me longer for me to do this in Python!
