# Weave hangs when trying to generate a plot

**URL:** <https://discourse.julialang.org/t/weave-hangs-when-trying-to-generate-a-plot/80617>\
**Category:** Visualization\
**Created:** [May 6, 2022, 2:08pm UTC](https://discourse.julialang.org/t/weave-hangs-when-trying-to-generate-a-plot/80617 "2022-05-06T14:08:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauldg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauldg/32/36026_2.png) [@pauldg](https://discourse.julialang.org/u/pauldg)\
**Post date:** [May 6, 2022, 2:08pm UTC](https://discourse.julialang.org/t/weave-hangs-when-trying-to-generate-a-plot/80617/1 "2022-05-06T14:08:21Z")

</div>

I have a histogram inside a jmd file that I want to plot:

````julia
```julia; echo = false
    using Plots
    gr()
    h = histogram(WEAVE_ARGS.dict["p_reads"], label="", 
                xlabel="Number of reads", 
                linecolor="white", 
                normalize=:probability,
                xtickfontsize=10,ytickfontsize=10,
                color=:mediumturquoise, size=(500,350), bins = 25,
                xlim=((25, 125)),
                ylabel="Relative frequency", 
                title="gRNA frequency distribution") ```

````

Which makes Weave hang:

```julia
┌ Info: Weaving chunk 1 from line 24
└ progress = 0.0
┌ Info: Weaving chunk 2 from line 46
└ progress = 0.25
┌ Info: Weaving chunk 3 from line 55
└ progress = 0.5

```

Plotting from the command line works fine:

```julia
julia> @time histogram(p_reads, label="", 
                   xlabel="Number of reads", 
                   linecolor="white", 
                   normalize=:probability,
                   xtickfontsize=10,ytickfontsize=10,
                   color=:mediumturquoise, size=(500,350), bins = 25,
                   xlim=((25, 125)),
                   ylabel="Relative frequency", 
                   title="gRNA frequency distribution")
  0.001918 seconds (7.75 k allocations: 329.570 KiB)

```

Any advice?

---

<div class="post-metadata">

**Author:** ![pauldg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauldg/32/36026_2.png) [@pauldg](https://discourse.julialang.org/u/pauldg)\
**Post date:** [May 6, 2022, 2:17pm UTC](https://discourse.julialang.org/t/weave-hangs-when-trying-to-generate-a-plot/80617/2 "2022-05-06T14:17:33Z")

</div>

It seems that when I create the histogram object outside of the .jmd file and instead send it to the .jmd file using `WEAVE_ARGS` it works fine.

**EDIT:** I spoke to soon, it just seems to randomly work fine and other times not, perhaps its due to the .jmd file or the image file being open somewhere and not able to close.

---

<div class="post-metadata">

**Author:** ![pauldg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pauldg/32/36026_2.png) [@pauldg](https://discourse.julialang.org/u/pauldg)\
**Post date:** [May 11, 2022, 11:40am UTC](https://discourse.julialang.org/t/weave-hangs-when-trying-to-generate-a-plot/80617/3 "2022-05-11T11:40:56Z")

</div>

Apparently this is a known bug reported here, including a workaround: [https://github.com/JunoLab/Weave.jl/issues/436](https://github.com/JunoLab/Weave.jl/issues/436).

```julia
ENV["GKSwstype"]="nul"
weave("00.jl", cache=:off, out_path="output/")
ENV["GKSwstype"]="gksqt"

```
