# Adding pdf/png into existing pgfplots

**URL:** https://discourse.julialang.org/t/adding-pdf-png-into-existing-pgfplots/89922
**Category:** General Usage
**Tags:** plotting, pgfplotsx
**Created:** [November 8, 2022, 10:32am UTC](https://discourse.julialang.org/t/adding-pdf-png-into-existing-pgfplots/89922 "2022-11-08T10:32:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Elyco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elyco/32/18418_2.png) [@Elyco](https://discourse.julialang.org/u/Elyco)
#### Post date: [November 8, 2022, 10:32am UTC](https://discourse.julialang.org/t/adding-pdf-png-into-existing-pgfplots/89922/1 "2022-11-08T10:32:02Z")

</div>

Hi,  
I’m trying to add a node to a pgfplot that contains a pdf/png file.

Here is what I have until now

```julia
using Plots
pgfplotsx()
fig1 = plot(1:5)
savefig(fig1, "fig1.png")
savefig(fig1, "fig1.pdf") # just to create a figure in the folder
fig2 = plot([1,2])
plot!(fig2,[NaN],add=raw"\pgfdeclareimage{img}{fig1.pdf}
\node (img1) at (1.5,1.25) {\pgfuseimage{img}};", extra_kwargs=:subplot)

```

But the file is not presented in the figure.  
The node tex code is taken from a [stack question.](https://tex.stackexchange.com/a/168968)  
 ![fig2](https://global.discourse-cdn.com/julialang/original/3X/7/4/746572e1a05e9e77a700e9473e6b1711911542dc.png)

I’ve already tried

```julia
f_pdf = load(file)
heatmap!(fig,f_pdf)

```

But it complains about memory issue, which I don’t understand (in `pfgplotsx()` backend).

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [November 8, 2022, 2:15pm UTC](https://discourse.julialang.org/t/adding-pdf-png-into-existing-pgfplots/89922/2 "2022-11-08T14:15:25Z")

</div>

I think you need the absolute path to that file:

```julia
using Plots
pgfplotsx()
fig1 = plot(1:5)
savefig(fig1, "fig1.png")
savefig(fig1, "fig1.pdf") # assuming this is run in homedir()
fig2 = plot([1,2])
plot!(fig2,[NaN],add="\\pgfdeclareimage{img}{$(homedir())/fig1.pdf}
\\node (img1) at (1.5,1.25) {\\pgfuseimage{img}};", extra_kwargs=:subplot)

```

---

<div class="post-metadata">

### Author: ![Elyco](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elyco/32/18418_2.png) [@Elyco](https://discourse.julialang.org/u/Elyco)
#### Post date: [November 8, 2022, 3:46pm UTC](https://discourse.julialang.org/t/adding-pdf-png-into-existing-pgfplots/89922/3 "2022-11-08T15:46:52Z")

</div>

Oh, thanks!  
Now it’s working!
