KristofferC / PGFPlotsX.jl

Plots in Julia using the PGFPlots LaTeX package
Other
301 stars 40 forks source link

Error in latex output for heat map. #222

Closed pstaabp closed 4 years ago

pstaabp commented 4 years ago

If you enter:

using Plots,PGFPlotsX
pgfplotsx()
heatmap(rand(10,10))

You get the expected output:

image

However, if it is saved using

savefig("heat.tex")

upon compiling in latex, the following error occurs:

! Missing number, treated as zero.
<to be read again> 
\pgfpl@cm@plots1@X@size 
l.117        };

where the line 117 is the end of the \addplot3 command. There are many many errors after that too.

tpapp commented 4 years ago

I am not sure this is a bug in this package, rather than the relevant backend of Plots.jl.

Code using PGFPlotsX only would be helpful to establish this.

@BeastyBlacksmith, can you please try replicating this with Plots?

BeastyBlacksmith commented 4 years ago

Thats due to the preamble, the following will work:

using Plots,PGFPlotsX
pgfplotsx()
heatmap(rand(10,10), tex_output_standalone = true)
savefig("heat.tex")
run(`lualatex heat.tex`)

However, if you want to use those .tex-files in another document, you can query the preamble with Plots.pgfx_preamble.

pstaabp commented 4 years ago

Yes, this seems like it works.

If I am embedding this in an existing document, do I need to add all of the packages that are included at the top? I'm guessing this is what you mean by the Plots.pgfx_preamble?

Is this in the documentation somewhere?

tpapp commented 4 years ago

I don't think this is an issue with PGFPlotsX, so I am closing. Perhaps the backend documentation of Plots.jl could mention the existence of pgfx_preamble, please open another issue at

https://github.com/JuliaPlots/Plots.jl/issues

BeastyBlacksmith commented 4 years ago

I added a section to the docs here

If I am embedding this in an existing document, do I need to add all of the packages that are included at the top?

Not neccessarily everything, since for example, if you don't do smithcharts you don't need to include that package. But if you include everything, it should work.

pstaabp commented 4 years ago

I appreciate the additional documentation. I tried the .tikz approach and a couple of thing.

  1. it appears that savefig saves the file with extension .tikz.tex, not .tikz. Was this supposed to happen?
  2. When using \includegraphics from graphicsx it didn't take either .tikz or .tex files. I get a ! LaTeX Error: Unknown graphics extension: .tex. . Is there a different package than graphicx that includes this?
  3. Lastly, when including the preamble, I found doing the following was helpful:
    open("preamble.tex", "w") do f
    write(f, Plots.pgfx_preamble(pl3) )
    end

and then in the preamble to the latex file, I needed to strip the second line which includes the standalone document class and then in the latex document include \input{preamble.tex} in the preamble of the tex document. This may be helpful for some.